解题思路:
A[n] = A[n-1] + N所对应的大写字母 + A[n-1]
比如: A1 = "" + A + ""
A2 = "A" + B + "A"
A3 = "ABA" + C + "ABA"
......
注意事项:
用 string 做就很开心啊,C++标准 重载好运算符了
参考代码:
#include<bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { string res = ""; for (int i = 0; i < n; ++i) { res = res + (char)('A' + i) + res; } cout << res << endl; // cout << res.length() << endl; // 这一行可以看字符串有多长,可以跑跑 N = 26 的结果 } return 0; }
0.0分
1 人评分