|
|
вернуться в форумNice recursive functions I thought i'll never get AC at this problem, but after some time i wrote that very nice (as for me ^___^) functions doing the work. void a( int n, int k ) { -printf("sin(%d",k); -if ( k < n ) -{ --if ( k % 2 ) ---printf("-"); --else ---printf("+"); --a( n, k + 1 ); -} -printf(")"); } void s( int n, int k ) { -if ( k < n ) -{ --printf("("); --s( n, k + 1 ); --printf(")"); -} -a( n - k + 1, 1 ); -printf("+%d",k); } For answer just need to call s( n, 1 ). Good luck! Edited by author 20.03.2010 18:23 Re: Nice recursive functions void s(int n, int k) { printf("sin(%d",k); if (n!=k) { putchar(((k&1)<<1)+43); s(n,++k); } putchar(')'); } void p(int n, int k) { if (k>1) { putchar('('); p(n,k-1); } s(k,1); printf("+%d",n+1-k); if (k<n) putchar(')'); } my algorithm... for answer p(n,n) Re: Nice recursive functions Thanks, I was stuck in the recursion for Sn. :) |
|
|