蓝桥杯 1463: [蓝桥杯][基础练习VIP]Sine之舞 Easy only once

基本思想:

利用递归或者循环结构找规律输出;

 

关键点:

能用递归用递归,比较简单;

不能则用循环处理;

 

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;



string An_construt(int m,int n) {
    if (n == m)
        return "sin(" + to_string(n) + ")";
    char c;
    if (m % 2 == 0)
        c = '+';
    else
        c = '-';
    return "sin(" + to_string(m) + c + An_construt(m +1, n) + ")";
}

string Sn_construct(int n) {
    string s;
    for (int i = 0; i < n - 1; i++) {
        s += '(';
    }
    for (int i = 0; i < n; i++) {
        s += An_construt(1, i + 1) + "+" + to_string(n - i)+")";
    }
    s.pop_back();
    return s;
}

int main(){
    int n;
    cin >> n;
    string s= Sn_construct(n);
    cout << s;
    return 0;
}

 

posted @ 2020-02-08 18:01  暮云林凌  阅读(193)  评论(0)    收藏  举报