Timus 1149. Sinus dances requires that strings in specific formats be output.
1149. Sinus dancestime limit: 1.0 second
Memory limit: 16 mblet
An= Sin (1-sin (2 + sin (3-sin (4 +... Sin (
N))...)
Let
Sn= (... (
A1 +
N)
A2 +
N-1)
A3 +... + 2)
An+ 1
For given
NPrint
SnInputone integer
N. 1 ≤
NLess than or equal to 200 outputline containing
SnSample
| Input |
Output |
3 |
((sin(1)+3)sin(1–sin(2))+2)sin(1–sin(2+sin(3)))+1 |
Problem Author:Vladimir gladkov
Problem Source:Ural Collegiate Programming Contest, limit L 2001, Perm, test round
Tags:Problem for beginners
C # language:
Using system; // http://acm.timus.ru/problem.aspx? Space = 1 & num = 1149 static class timus {const int max = 200; static char [] MSG = "Sin () + -". tochararray (); static char [] A = new char [Max * 10]; static char [] S = new char [Max * 5 * max]; static void main () {console. writeline (S, 0, makes (Int. parse (console. readline ();} static int makes (int n) {var COUNT = 0; while (count <n-1) s [count ++] = MSG [3]; // '(' For (int K, I = 1; I <= N; I ++, Count ++) {Var n = (n-I + 1 ). tostring (). tochararray (); array. copy (A, 0, S, Count, K = makea (I); // AI s [count + = K] = MSG [5]; // '+' array. copy (n, 0, S, ++ count, N. length); // n-I + 1 s [count + = n. length] = MSG [4]; // ')'} return -- count; // remove the last ')'} static int makea (int n) {var COUNT = 0; for (VAR I = 1; I <= N; I ++, Count ++) {var n = I. tostring (). tochararray (); array. copy (MSG, 0, A, Count, 4 ); // "Sin (" array. copy (n, 0, A, Count + = 4, N. length); // I A [count + = n. length] = MSG [(I % 2 = 0 )? 5: 6]; // '+' or '-'} count --; // overwrite the last '+' or '-' For (VAR I = 0; I <N; I ++) A [count ++] = MSG [4]; // ') 'Return count ;}}
This question and answer are very simple and I will not explain it.
Returned directory