Problem A: A + B
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 17 Solved: 10
[Submit][Status][Web Board] [Edit] [TestData]
Description
读入两个小于10000的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.

Input
测试输入包含若干测试用例,每个测试用例占一行,格式为”A + B =”,相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.

Output
对每个测试用例输出1行,即A+B的值.

Sample Input
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
Sample Output
3
90
96

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
string a[];//分别存放‘+’号前英文
char a1[];//存放英文对应的数字字符
string b[];//存放加号后,等号前的英文
char b1[];//存放英文对应的数字字符
int k,shu1,shu2;
int g;
while()
{
memset(a1,'\0',sizeof(a1));//初始化
memset(b1,'\0',sizeof(b1));//初始化
int i=;
int j=;
while(cin>>a[i])
{
if(a[i][]=='+')
{
i--;
break; //存放加号前的英文词
}
i++;
}
while(cin>>b[j])
{
if(b[j][]=='=')
{
j--; //存放加号后,等于号前的英文词
break;
}
j++;
}
if(a[]=="zero"&&i==||b[]=="zero"&&j==)
{
break; //如果是zero + zero =的话,直接终止程序
}
g=;
for(k=;k<=i;k++)
{
if(a[k]=="zero")
a1[g++]='';
if(a[k]=="one")
a1[g++]='';
if(a[k]=="two")
a1[g++]='';
if(a[k]=="three")
a1[g++]='';
if(a[k]=="four")
a1[g++]='';
if(a[k]=="five")
a1[g++]='';
if(a[k]=="six")
a1[g++]='';
if(a[k]=="seven")
a1[g++]='';
if(a[k]=="eight")
a1[g++]='';
if(a[k]=="nine")
a1[g++]='';
}
sscanf(a1,"%d",&shu1); //将存放在a1数组中的字符变成整型,存放在shu1中
g=; // g变成0
for(k=;k<=j;k++)
{
if(b[k]=="zero")
b1[g++]='';
if(b[k]=="one")
b1[g++]='';
if(b[k]=="two")
b1[g++]='';
if(b[k]=="three")
b1[g++]='';
if(b[k]=="four")
b1[g++]='';
if(b[k]=="five")
b1[g++]='';
if(b[k]=="six")
b1[g++]='';
if(b[k]=="seven")
b1[g++]='';
if(b[k]=="eight")
b1[g++]='';
if(b[k]=="nine")
b1[g++]='';
}
sscanf(b1,"%d",&shu2); //将存放在b1数组中的字符变成整型,存放在shu2中
cout<<shu1+shu2<<endl; //求和
}
return ;
}

Problem A: A + B的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. 编程珠玑I算法总结

    主要是根据编程珠玑后面的Algorithm附录总结了一下这本书里面的经典算法. 1 辗转相减求最大公约数 思想:最大公约数能整除i和j,则其一定也能整除i-j(if i>j) int gcd(i ...

  2. C语言入门(9)——局部变量与全局变量

    变量有效性的范围称变量的作用域.C语言中所有的量都有自己的作用域.变量说明的方式不同,其作用域也不同. C语言中的变量,按作用域范围可分为两种,即局部变量和全局变量.   局部变量 局部变量也称为内部 ...

  3. 练习一下linux中的list函数。

    所有的list函数见 include/linux/list.h 自己从 include/linux/list.h 拷贝了一些函数到自己的list.c中, 然后练习了一下. 没有别的目的,就是想熟练一下 ...

  4. twisted的一些代码

    之前用swoole(1.7.19)写的一段程序在数据量大的时候存在内存泄漏,改为twisted(15.4)实现,自测无误,记录如下(两者cpu占用率90%时吞吐rps能从120提升到1000). #! ...

  5. POJ 2342 树形DP入门题

    有一个大学的庆典晚会,想邀请一些在大学任职的人来參加,每一个人有自己的搞笑值,可是如今遇到一个问题就是假设两个人之间有直接的上下级关系,那么他们中仅仅能有一个来參加,求请来一部分人之后,搞笑值的最大是 ...

  6. xcode - 触摸移动

    第一步 创建一个UIView类  命名MoveView #import "MoveView.h" @implementation MoveView /** 移动事件 */ -(vo ...

  7. NET,ASP.NET,C#,WinFrom之间的联系与区别

    1:C#是编程语言(静态,强类型).类似中文.德文.英文这样. 2:.NET是一个平台(可承载多个编程语言,比如C# C++.net J# VB.Net),       但是都是运行在.net Fra ...

  8. 2014.9.15HTML

    <html> <title> </title> ——页面标题 <head> </head> ——网页上的控制信息 <body> ...

  9. qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】

    #include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...

  10. Sunny谈软件架构

    软件架构是软件工程一个很重要的分支,随着软件规模的扩大和软件寿命的延长,软件架构也越发重要.就像建筑领域,盖一个狗窝不需要进行分析与设计,但是如果是要盖一座万人体育场或者摩天大楼,那一定会离不开设计师 ...