ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1149. Sinus Dances

Accepted Java
Posted by magzhan 22 Jun 2011 14:14
import java.util.*;

public class Problem {

    public static void a(int n) {
        for(int i=1;i<=n;i++){
            if(i==n){
                System.out.print("sin("+Integer.toString(i));
            }else{
                if(i%2==1){
                    System.out.print("sin("+Integer.toString(i)+"-");
                }else{
                    System.out.print("sin("+Integer.toString(i)+"+");
                }
            }
        }
        for(int i=0;i<n;i++){
            System.out.print(")");
        }
    }

    public static void s(int n){
        for(int i=0;i<n-1;i++){
            System.out.print("(");
        }
        for(int i=1;i<n;i++){
            a(i);
            System.out.print("+"+Integer.toString(n+1-i)+")");
        }
        a(n);
        System.out.print("+1");
    }

    public static void main (String[] args) {
        try {

            Scanner in = new Scanner(System.in);

            int n=in.nextInt();

            s(n);

        } catch (Exception ex) {

            System.out.println(ex.toString());
        }
    }
}