import java.util.Scanner; public class Main{ /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); System.out.println(s(Integer.parseInt(scanner.nextLine()), 1)); //System.out.print(sin(3, 1)); } static String s(int n,int i) { if(i==n) { return ""+An(n)+"+"+(n-i+1); } else { return "("+An(i)+"+"+(n-i+1)+")"+""+s(n, i+1)+""; } } static String An(int n) { return sin(n, 1); } static String sin(int n,int i) { if(i==n) { return "sin("+n+")"; } else { if(i%2==0) return "sin("+i+"+"+sin(n, i+1)+")";//(int)Math.pow(-1,i) else { return "sin("+i+"-"+sin(n, i+1)+")"; } } } }
蓝桥杯—— 基础练习之Sine之舞,布布扣,bubuko.com
原文:http://blog.csdn.net/hymanxq/article/details/26082479