清风与酒f42ij 题解分享 · 2026/4/6
字符串编号——题解
include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s,t;//定义string类型的变量s和t,s用来输入数字序列,t用来存放后续提取的子串 int sd;//sd用来将提取的数字子串转换为数字,对应上26个字母的下标 cin>>s; char zm[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'}; //创建字母数组,注意A从下标为1的地方开始 for(int i=0;i =1&&sd<=26)//判断如果数字在1-26之间,那我们可以直接输出这个数字下标对应的字母 { cout<<zm[sd]; i++;//完成之后i要加1,因为进入这个if条件意味着我们提取的是两位数字字符 //之后for循环里面也还要加1,下一个子串从已经提取过后的剩下的子串的第一位开始提取 } else//如果提取的两位字符转为数字后超出了字母的下标范围 { t=s.substr(i,1);//这时我们只提取一位数字字符放入t当中 sd=stoi(t);//将其转换为数字 cout<<zm[sd];//输出其对应下标的字母 } } return 0; }
查看全文
2 0 0 33
CQS 题解分享 · 2025/3/5
字符串编号(编程题) - 题解
``` #include <iostream> #include <string> using namespace std; int main() { string str1; cin >> str1; int len = str1.size(); string str2; int i = 0; while (i < len) { if (stoi(str1.substr(i, 2)) <= 26) { str2 += (char)(stoi(str1.substr(i, 2)) + 64); i += 2; } else { str2 += (char)(stoi(str1.substr(i, 1)) + 64); i ++; } } cout << str2 <<endl; return 0; } ```
查看全文
4 0 0 477
yuri01 题解分享 · 2024/12/26
字符串编号(编程题) - 题解
```cpp // A -> 1 Z -> 26 #include <bits/stdc++.h> using namespace std; string ss = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { string str; cin >> str; for (int i = 0; i < str.size();) { string s2 = str.substr(i, 2); string s1 = str.substr(i, 1); if (s2 <= "26") { int x = stoi(s2); cout << ss[x]; i += 2; } else { int x = stoi(s1); cout << ss[x]; i++; } } return 0; } ```
查看全文
5 0 0 9
kaisyuantseng 题解分享 · 2024/4/11
字符串编号(编程题) - 题解
```cpp #include <bits/stdc++.h> using namespace std; #define int long long // #define LL long long #define endl '\n' void solve() { string s; cin >> s; for (int i = 0; i < s.length(); i++) { int num = stoi(s.substr(i, 2)); if (num <= 26) { printf("%c", 'A' + num - 1); i++; } else printf("%c", 'A' + (s[i] - '0') - 1); } } signed main() { // ios::sync_with_stdio(0); // cin.tie(0), cout.tie(0); solve(); return 0; } ```
查看全文
5 0 0 505
Liopen 题解分享 · 2024/4/13
字符串编号(编程题) - 题解
``` #include<cstdio> #include<iostream> #include<string> using namespace std; int main(){ string s; cin>>s; int one,two; char a[27]; for (int i=1;i<=26;++i){ a[i]= 'A'+i-1; } for(int i=0;i<s.length();i++){ one=s[i]-'0'; if(i!=s.length()-1) two=10*one+s[i+1]-'0'; if(two<=26&&two!=0){ cout<<a[two]; i++; two=0; } else{ cout<<a[one]; } } return 0; } ```
查看全文
5 0 0 492
itlinyi 题解分享 · 2024/4/11
字符串编号(编程题) - 题解
``` // // Created by 30945 on 2024/4/11. // #include<bits/stdc++.h> #define int long long #define endl '\n' using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; getline(cin, s); for (int i = 0; i < s.length(); ++i) { char c; string a = s.substr(i, 2); if (stoi(a) <= 26) { c = stoi(a) + ('A' - 1); i++; } else { string a = s.substr(i, 1); c = stoi(a) + ('A' - 1); } cout << c; } return 0; } ```
查看全文
5 0 0 490
less 题解分享 · 2024/4/6
字符串编号(编程题) - 题解
include using namespace std; int main() { string s; getline(cin, s); char m; int n = s.size(); ``` int i; for (i = 0; i < n; i++) { if (s[i] == '1' && s[i + 1] <= '9' && s[i + 1] >= '0') { m = 'A' + 10 + s[i + 1] - '1'; i++; cout << m; } else if (s[i] == '2' && s[i + 1] <= '6' && s[i + 1] >= '0') { m = 'A' + 20 + s[i + 1] - '1'; i++; cout << m; } else { m = 'A' + s[i] - '1'; cout << m; } } return 0; ``` }
查看全文
5 0 0 483
seabra 题解分享 · 2024/4/9
字符串编号(编程题) - 题解
include using namespace std; int main(){ string s; string str; cin>>s; int i=0; while(i<s.size()){ if(i+2<=s.size()){ int n=stoi(s.substr(i,2)); if(n<=26){ char x='A'+n-1; str+=x; i+=2; } else{ int m=s[i]-'0'; char x='A'+m-1; str+=x; i++; } } else{ int m=s[i]-'0'; char x='A'+m-1; str+=x; i++; } } cout<<str; return 0; }
查看全文
4 0 1 501
NorthChern 题解分享 · 2024/4/6
字符串编号(编程题) - 题解
``` import java.util.Scanner; public class Main { //1.每次两个数字两个数字地选取 //2.如果当前数字大于26,就选取上一个数字 static char[] table = {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'}; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] c = scanner.next().toCharArray(); StringBuilder res = new StringBuilder(); //使用StringBuilder进行优化 int n = c.length; for (int i = 0; i < n; i++) { if(i + 1 == n){ res.append(table[c[i] - '0']); break; } int big = c[i] - '0'; int small = c[i + 1] - '0'; int num = big * 10 + small; if (num <= 26) { res.append(table[num]); i++; } else { res.append(table[big]); } } System.out.print(res); } } ```
查看全文
4 0 1 485
薛时锦 题解分享 · 2024/4/7
字符串编号(编程题) - 题解
``` #include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int len = s.size(); string str; int i = 0; while(i < len){ if (stoi(s.substr(i,2)) <= 26) { str += (char)(stoi(s.substr(i,2)) + 64); i += 2; }else{ str += (char)(stoi(s.substr(i,1)) + 64); i ++; } } cout << str; return 0; } ```
查看全文
2 0 4 495