小豆子范德萨 @ 2018-06-22 17:36:42
自己电脑上IDE调试,最起码第一个样例过了,提交OJ上连第一个样例都过不了,是不是抽风了???代码如下:
#include <bits/stdc++.h>
using namespace std;
string s[30] = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty","a","both","another","first","second","third"};
int a[] = {0,1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,1,4,1,1,4,9};
int b[7]; //用来存放每个单词对应的密码
int main(void){
string str; //存放单词
int j = 0;
while(cin>>str && str != "."){
for(int i = 0;i < 30;i++){
if(s[i] == str) { b[j++] = a[i];break;}
}
}
sort(b,b+j); //快速排序,把值小的放前面
bool flag = false; //标志,当密码
for(int i = 0;i < j;i++){
if(flag == false && b[i] == 0) continue;
else if(flag == false && b[i] < 10) printf("%d");
else if(flag == true && b[i] < 10) printf("%02d");
else{
printf("%2d",b[i]);
flag = true;
}
}
return 0;
}
by 小豆子范德萨 @ 2018-06-22 17:54:32
好吧,sb了。printf函数格式控制没写