Ural 1149 - Sinus Dances

Let An = sin(1–sin(2+sin(3–sin(4+…sin(n))…)
Let Sn = (…(A1+n)A2+n–1)A3+…+2)An+1
For given N print SN

Input

One integer N. 1 ≤ N ≤ 200

Output

Line containing SN

Sample

inputoutput
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, April 2001, Perm, Test Round
// Ural Problem 1149. Sinus Dances
// Verdict: Accepted  
// Submission Date: 15:58:23 15 Jan 2014
// Run Time: 0.093s
//  
// 版权所有(C)acutus   (mail: acutus@126.com) 
// 博客地址:http://www.cnblogs.com/acutus/
// [解题方法]  
// 简单字符串处理
// 注意:所有符号之间没有空格

#include<stdio.h>

void An(int n)
{
    int i;
    for(i = 1; i < n; i++) {
        printf("sin(%d", i);
        if(i%2) printf("-");
        else printf("+");
    }
    printf("sin(%d", n);
    for(i = 1; i <= n; i++) {
        printf(")");
    }
}

void Sn(int n)
{
    int i;
    for(i = 1; i < n; i++) {
        printf("(");
    }
    for(i = 1; i < n; i++) {
        An(i);
        printf("+%d)", n - i + 1);
    }
    An(n);
    printf("+1\n");
}

void solve()
{
    int N;
    scanf("%d", &N);
    Sn(N);
}

int main()
{
    solve();
    return 0;
}

 

posted @ 2014-01-15 16:04  acutus  阅读(251)  评论(0编辑  收藏  举报
TOP