SWUSTOJ #287 one + two = 3
SWUSTOJ #287 one + two = 3
- 题目
- 输入
- 输出
- 样例输入
- 样例输出
- 源代码
题目
读入两个小于100的正整数A和B,计算A+B。需要注意的是:A和B的每一位数字由对应的英文单词给出。
输入
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。
输出
对每个测试用例输出1行,即A+B的值。
样例输入
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出
3
90
96
源代码
#include <stdio.h>
#include <string.h>int num1(char a[])
{if(strcmp(a,"one") == 0) return 1;else if(strcmp(a,"two") == 0) return 2;else if(strcmp(a,"three") == 0) return 3;else if(strcmp(a,"four") == 0) return 4;else if(strcmp(a,"five") == 0) return 5;else if(strcmp(a,"six") == 0) return 6;else if(strcmp(a,"seven") == 0) return 7;else if(strcmp(a,"eight") == 0) return 8;else if(strcmp(a,"nine") == 0) return 9;else if(strcmp(a,"zero") == 0) return 0;
}
int num2(char a[])
{if(strcmp(a,"one") == 0) return 1;else if(strcmp(a,"two") == 0) return 2;else if(strcmp(a,"three") == 0) return 3;else if(strcmp(a,"four") == 0) return 4;else if(strcmp(a,"five") == 0) return 5;else if(strcmp(a,"six") == 0) return 6;else if(strcmp(a,"seven") == 0) return 7;else if(strcmp(a,"eight") == 0) return 8;else if(strcmp(a,"nine") == 0) return 9;else if(strcmp(a,"zero") == 0) return 0;
}
int main()
{char a[20];while(1){int sum=0, sum1=0, sum2=0;scanf("%s", a);sum1=num1(a);scanf("%s", a);if(strcmp(a,"+") != 0){sum1 = sum1*10 + num1(a);scanf("%s", a);}scanf("%s", a);sum2 = num2(a);scanf("%s", a);if(strcmp(a,"=") != 0){sum2 = sum2*10 + num2(a);scanf("%s", a);}sum = sum1 + sum2;if(sum == 0)break;elseprintf("%d\n", sum);}return 0;
}
SWUSTOJ #287 one + two = 3
SWUSTOJ #287 one + two = 3
- 题目
- 输入
- 输出
- 样例输入
- 样例输出
- 源代码
题目
读入两个小于100的正整数A和B,计算A+B。需要注意的是:A和B的每一位数字由对应的英文单词给出。
输入
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。
输出
对每个测试用例输出1行,即A+B的值。
样例输入
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出
3
90
96
源代码
#include <stdio.h>
#include <string.h>int num1(char a[])
{if(strcmp(a,"one") == 0) return 1;else if(strcmp(a,"two") == 0) return 2;else if(strcmp(a,"three") == 0) return 3;else if(strcmp(a,"four") == 0) return 4;else if(strcmp(a,"five") == 0) return 5;else if(strcmp(a,"six") == 0) return 6;else if(strcmp(a,"seven") == 0) return 7;else if(strcmp(a,"eight") == 0) return 8;else if(strcmp(a,"nine") == 0) return 9;else if(strcmp(a,"zero") == 0) return 0;
}
int num2(char a[])
{if(strcmp(a,"one") == 0) return 1;else if(strcmp(a,"two") == 0) return 2;else if(strcmp(a,"three") == 0) return 3;else if(strcmp(a,"four") == 0) return 4;else if(strcmp(a,"five") == 0) return 5;else if(strcmp(a,"six") == 0) return 6;else if(strcmp(a,"seven") == 0) return 7;else if(strcmp(a,"eight") == 0) return 8;else if(strcmp(a,"nine") == 0) return 9;else if(strcmp(a,"zero") == 0) return 0;
}
int main()
{char a[20];while(1){int sum=0, sum1=0, sum2=0;scanf("%s", a);sum1=num1(a);scanf("%s", a);if(strcmp(a,"+") != 0){sum1 = sum1*10 + num1(a);scanf("%s", a);}scanf("%s", a);sum2 = num2(a);scanf("%s", a);if(strcmp(a,"=") != 0){sum2 = sum2*10 + num2(a);scanf("%s", a);}sum = sum1 + sum2;if(sum == 0)break;elseprintf("%d\n", sum);}return 0;
}
发布评论