专栏文章
题解:P1603 斯诺登的密码
P1603题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mioqabxy
- 此快照首次捕获于
- 2025/12/02 23:23 3 个月前
- 此快照最后确认于
- 2025/12/02 23:23 3 个月前
This is my first solution......
我的解法和别人的不同之处在于:
- 将基数词放在一起,序数词放在一起,a 和 both 放在一起,another 单独一组,这样可以直接用下标作为转换后的数字。
- 用
to_string(i*i%100);来进行操作,可有效地节省空间。
Code:
CPP#include<bits/stdc++.h>
using namespace std;
bool cmp(const string &a,const string &b){
return (a+b<b+a);
}
string s,k,p;
string j[21]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
string x[21]={"0th","first","second","third"};
string f[21]={"0","a","both"};
string v="another";
int a,q;
string g[7];
int main(){
getline(cin,s);
for(int ii=0;ii<s.size();ii++){
if(s[ii]>='A'&&s[ii]<='Z'){
s[ii]+=32;//注意大小写
}
if(s[ii]==' '){
for(int i=0;i<=20;i++){
if(k==j[i]||k==x[i]||k==f[i]){
q++;
g[++a]=to_string(i*i%100);
if(g[a].size()==1){
g[a].insert(0,"0");
}
}
}
if(k==v){
q++;
g[++a]="01";
}
k="";
}else{
k+=s[ii];
}
}
sort(g+1,g+a+1,cmp);
for(int i=1;i<=a;i++){
p+=g[i];
}
while(p[0]=='0'){
p.erase(0,1);
}
if(q==0){//如果没有合法的数字
cout<<q;
}else{
cout<<p;
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...