int main()
{
char a[10][10] = {“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”};
char str[100];
int i,T=0,j, y = 0, z = 0, sum = 0, b = 0, d = 0, e = 0;
scanf(“%d”,&T);
for(i=0;i<T;i++)
{
y = 0;
z = 0;
sum = 0;
b = 0;
d = 0;
e = 0;
补个更简单(懒)的写法
转换为大数加法
include
using namespace std;
int main() {
int n;
}
include
int strlen(char p){
int i=0;
while(p[i]!=’\0’){
i++;
}
return i;
}
int equals(char str1,char str2){
if(strlen(str1)!=strlen(str2))return 0;
else{
int len=strlen(str1);
for(int i=0;i<=len-1;i++){
if(str1[i]!=str2[i])return 0;
}
return 1;
}
}
int getnum(char p){
int len=strlen(p);
int bigger=0;
int i;
for(i=0;i<=len-1;i++){
if(p[i]==’ ‘){
bigger=1;
break;
}
}
if(!bigger){
if(equals(p,”zero”))return 0;
if(equals(p,”one”))return 1;
if(equals(p,”two”))return 2;
if(equals(p,”three”))return 3;
if(equals(p,”four”))return 4;
if(equals(p,”five”))return 5;
if(equals(p,”six”))return 6;
if(equals(p,”seven”))return 7;
if(equals(p,”eight”))return 8;
if(equals(p,”nine”))return 9;
}else{
char substr1[10],substr2[10];
int j;
for(j=0;j<i;j++){
substr1[j]=p[j];
}
substr1[j]=’\0’;
for(j=i+1;j<=len-1;j++){
substr2[j-i-1]=p[j];
}
substr2[j-i-1]=’\0’;
return getnum(substr1)10+getnum(substr2);
}
}
void getstrnum(char num1,char *num2){
int i=0;
char temp;
while((temp=getchar())!=’+’){
num1[i]=temp;
i++;
}
num1[i-1]=’\0’;
i=0;
getchar();
while((temp=getchar())!=’=’){
num2[i]=temp;
i++;
}
num2[i-1]=’\0’;
getchar();
}
int main(){
char num1[20],num2[20];
int N;
scanf(“%d”,&N);
getchar();
for(int i=0;i<=N-1;i++){
getstrnum(num1,num2);
printf(“case #%d:\n%d\n”,i,getnum(num1)+getnum(num2));
}
return 0;
}
先把字符串中所有的单词分离出来,放在二维数组中。
前两个单词放在二维数组的第一个和第二个,后两个单词放在二维数组的倒数第三个和倒数第二个里面;
然后再分别计算出所代表的数字相加即可。
、、、
include
include
include
include
include
void solve()
{
char a[10][10]={“zero”,”one”,”two”,”three”,”four”,”five”,”six”,”seven”,”eight”,”nine”};
int p=0,q=0;
char str[35];
char code[7][7];
memset(code,0,sizeof(code));
gets(str);
int cnt=0, i, j=0,k;
while(str[j])
{
k=0;
while(str[j]>=’a’&&str[j]<=’z’)
code[cnt][k++]=str[j++];
code[cnt][k]=’\0’;
cnt++;
}
int main()
{
int j, t;
//init();
scanf(“%d”,&t);
getchar();
for(j=0;j<t;j++)
{
printf(“case #%d:\n”,j);
solve();
}
return 0;
}
include
include
include
int main()
{
char a[10][10] = {“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”};
char str[100];
int i,T=0,j, y = 0, z = 0, sum = 0, b = 0, d = 0, e = 0;
scanf(“%d”,&T);
for(i=0;i<T;i++)
{
y = 0;
z = 0;
sum = 0;
b = 0;
d = 0;
e = 0;
}