底层群友


私信TA

用户名:uq_12459991393

访问量:1454

签 名:

等  级
排  名 5431
经  验 1481
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:
先通过递归求An,再通过递归求Sn
注意事项:
设一个全局变量
参考代码:

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.util.Scanner;


public class Main {

static int n;

static int i = n;

static Scanner sc = new Scanner(new InputStreamReader(System.in));

    static OutputStreamWriter out = new OutputStreamWriter(System.out);

public static void main(String[] args) throws Exception  {

Main.n = sc.nextInt();

Main.i = Main.n;

out.write(dfs(n));

        out.flush();

    }

public static String bfs(int n){  //求An


if(n==1) return "sin(1";

if((n&1)==0) return bfs(n-1)+"-sin("+n;

else return bfs(n-1)+"+sin("+n;


}

public static String dfs(int n){   //求Sn


if(n==1){

String s = bfs(1)+")";

return s+"+"+i;

}

String s = bfs(n);

String s1 = bfs(n);


while(s.contains("(")){

s = s.substring(s.indexOf("(")+1, s.length());

s1 += ")";

}

return "("+dfs(n-1)+")"+s1+"+"+ --Main.i;

}

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区