样例不过

P1603 斯诺登的密码

511_Juruo_wyk @ 2023-12-06 21:59:37

#include<bits/stdc++.h>
using namespace std;
const int N = 26;
pair<string,int>p[N]={{"one",1},{"two",4},{"three",9},{"four",16},{"five",25},{"six",36},{"seven",49},{"eight",64},{"nine",81},
                      {"ten",0},{"eleven",21},{"twelve",44},{"tirteen",69},{"fourteen",96},{"fifteen",25},{"sixteen",56},
                      {"seventeen",89},{"eighteen",24},{"nineteen",61},{"twenty",0},{"a",1},{"both",4},{"another",1},
                      {"first",1},{"second",4},{"third",9}};
int num[10],top;
int member(string s){
    for(int i=0;i<N;i++)
        if(s==p[i].first)return p[i].second;
    throw s;
}
int main(){
    string s;
    for(int i=1;i<=6;i++){
        cin>>s;
        try {num[++top]=member(s);}
        catch(string){top--;}
    }
    sort(num+1,num+1+top);
    bool flag=true;
    for(int i=2;i<=top;i++){
        if(flag&&num[i]!=0)cout<<num[i],flag=false;
        else printf("%02d",num[i]);
    }
    return 0;
}

by 511_Juruo_wyk @ 2023-12-06 22:07:31

我太惨了,我用的是DEV-C++,如果给结构体、STL数组等直接用大括号赋值就会给予警告,然后DEV-C++就崩溃了


by 511_Juruo_wyk @ 2023-12-06 22:26:22

哦对了,try...catch语句我一开始没加大括号报错了(try后面只有一行语句),有木有dl帮我解释一下为啥try...catch语句必须要加大括号?谢谢!


|