-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_1149.cpp
44 lines (33 loc) · 1 KB
/
task_1149.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
std::string get_a(int n) {
std::string result = "sin(" + std::to_string(n) + ")";
std::reverse(result.begin(), result.end()); // using reverse to append result to string and then add ')' symbol
std::string temp;
for (int i = n - 1; i > 0; i--) {
temp = "sin(" + std::to_string(i) + (i % 2 == 0 ? "+" : "-");
result.append(temp.rbegin(), temp.rend()); // reversed
}
std::reverse(result.begin(), result.end());
for (int i = 0; i < n - 1; i++)
result += ")";
return result;
}
std::string get_s(int n) {
std::string result;
for (int i = 0; i < n - 1; i++)
result += "(";
result += get_a(1) + "+" + std::to_string(n);
for (int i = 2; i <= n; i++)
result += ")" + get_a(i) + "+" + std::to_string(n - i + 1);
return result;
}
int main() {
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
std::cout << get_s(n);
return 0;
}