wangderui111 @ 2024-01-25 16:44:17
#include<bits/stdc++.h>
using namespace std;
string temp[27] = {"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 tempf[27] = {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};
string a[6];
int main() {
bool ll = false, lll = true;
cin >> a[0];
cin >> a[1];
cin >> a[2];
cin >> a[3];
cin >> a[4];
cin >> a[5];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 27; j++) {
if (a[i] == temp[j] && ll == false) {
cout << tempf[j];
ll = true;
continue;
} else if (a[i] == temp[j]) {
printf("%02d", tempf[j]);
ll = true;
continue;
}
}
}
if (ll == false) {
cout << 0;
}
return 0;
}
第一个事例错了,为啥不能加00???
by __lihaoyu68__ @ 2024-04-22 15:10:06
#include<bits/stdc++.h>
using namespace std;
char dic[30][20]= {"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 di[30]= {0,1,4,9,16,25,36,49,64,81,00,21,44,69,96,25,56,89,24,61,0,1,4,1,1,4,9};
unsigned long long int a[10],top,flag;
int i,j;
char s[100];
int main() {
for(i=1; i<=6; i++) {
scanf("%s",&s);
for(j=1; j<=26; j++) {
if(!strcmp(s,dic[j])) {
a[++top]=di[j];
break;
}
}
}
sort(a+1,a+top+1);
for(i=1; i<=top; i++) {
if(flag) {
printf("%.2d",a[i]);
} else {
if(a[i]) {
printf("%d",a[i]);
flag=1;
}
}
}
if(!flag)printf("0");
return 0;
}