题目1010:A + B(字符串转数字)
题目链接:http://ac.jobdu.com/problem.php?pid=1010
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
// // 1010 A + B.cpp // Jobdu // // Created by PengFei_Zheng on 28/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <cstring> #include <string.h> #include <cmath> #include <vector> using namespace std; #include <stdio.h> #include <string.h> char arr[10][8] = { "zero","one","two","three","four","five","six","seven","eight","nine"}; int find(char* str) { int i; for (i = 0; i < 10; i++) { if (strcmp(arr[i], str) == 0) return i; } return 0; } int main() { char temp[8]; while (scanf("%s", temp) != EOF) { int a = find(temp); scanf("%s", temp); if (temp[0] != '+') { a = a * 10 + find(temp); scanf("%s", temp); } scanf("%s", temp); int b = find(temp); scanf("%s", temp); if (temp[0] != '=') { b = b * 10 + find(temp); scanf("%s", temp); } if(a==0 && b==0) break; printf("%d\n", a + b); } return 0; } /************************************************************** Problem: 1010 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/
作者: 伊甸一点
出处: http://www.cnblogs.com/zpfbuaa/
本文版权归作者伊甸一点所有,欢迎转载和商用(须保留此段声明),且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文链接 如有问题, 可邮件(zpflyfe@163.com)咨询.