题解分享
题解分享简介
年号字串(结果填空) - 题解
模拟进位
```cpp
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
using ll = long long;
int main() {
int v = 2019;
string res = "A";
for (int i = 1; i < v; ++i) {
bool up = false;
for (int j = res.size() - 1; j >= 0; --j) {
up = 0;
++res[j];
if (res[j] > 'Z') {
up = 1;
res[j] = 'A';
}
if (!up)
break;
}
if (up)
res.push_back('A');
}
cout << res << '\n';
return 0;
}
```
查看全文
0
0
1
0
年号字串(结果填空) - 题解
26进制转换
```
#include <iostream>
#include <string>
using namespace std;
string f(int n) {
string res;
while (n) {
n--; // 从1开始计数,所以先减1
res= char('A' + n % 26) + res;
n /= 26;
}
return res;
}
int main() {
int n = 2019;
cout << f(n) << endl;
return 0;
}
```
查看全文
0
0
1
1
年号字串(结果填空) - 题解
```
import java.util.Scanner;
public class 年号字串 {
public static void main(String[] args) {
// 创建一个Scanner对象,用于接收用户输入
Scanner scanner = new Scanner(System.in);
// 定义一个字符串a,用于表示26进制数字的映射表
String a = "ZABCDEFGHIJKLMNOPQRSTUVWXY";
// 从用户输入中获取一个整数n
int n = scanner.nextInt();
// 当n不为0时,进行循环
while (n != 0) {
// 输出映射表中对应于n mod 26的字符
System.out.print(a.charAt(n % 26));
// 将n除以26,以便在下一次迭代中处理高位数字
n /= 26;
}
// 关闭Scanner对象,释放资源
scanner.close();
}
}
```
查看全文
0
0
0
7
年号字串(结果填空) - 题解
```
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
char a[27]={'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char> v;
int main()
{
int x=2019;
while(x)
{
v.push_back(a[x%26]);
x/=26;
}
reverse(v.begin(),v.end());
for(auto i:v)cout<<i;
return 0;
}
```
查看全文
0
0
0
6
年号字串(结果填空) - 题解
```
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
string str = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
int n;
string res;
cin >> n;
while(n)
{
res.push_back(str[n%26 - 1]);
n/=26;
}
reverse(res.begin(), res.end());
cout << res;
return 0;
}
```
查看全文
0
0
0
1



