Problem A: A + B
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的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [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 ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- Linux的正常关机
Azure上的 IaaS 虚拟机可使用多种方式关闭,例如通过 Azure 管理门户.Azure Powershell cmdlet 或 CLI 工具,甚至还可以由交互式登录的用户关闭.Azure 平台 ...
- Day4_代码重用与函数
知识点速记: 重用代码的方法:脚本包含require().include(); 全局配置文件php.ini(auto_prepend_file/auto_append_file); 目录配置文件.ht ...
- 【POJ】3009 Curling 2.0 ——DFS
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11432 Accepted: 4831 Desc ...
- [置顶] 北漂的大三IT男(暂完)
今天是2013年8月9日,是我待在北京的最后一个晚上,今天我已经正式向公司提出辞职了,虽然公司已经答应从下个月起涨部分工资,但是我还是坚决的离开了,回想当时进公司的想法----------干了一个月后 ...
- 利用UIScrollView和UIPageControl实现多页图片欢迎页面
在.h文件当中实现UIScrollViewDelegate协议,让控制器充当代理: #import <UIKit/UIKit.h> @interface RPRootViewControl ...
- poj 3680 Intervals(费用流)
http://poj.org/problem?id=3680 巧妙的构图. 题目:给定N个区间(ai,bi)权值wi,求最大权和且每个点最多覆盖K次. 构图:将区间端点离散化,将第i个点连第i+1个点 ...
- nyist 303序号互换(数学推理)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=303 思路: 开始看错题了,以为最多只有两个字母. 字母转数字的表达式很容易看出来是:(2 ...
- jquery新增,删除 ,修改,清空select中的option
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...
- 8月9日,PS、计算机基础(预科)
一. PS 掌握简单的图标修改. 1.图层 2.保存PSD格式,有图层:JPG格式,没有图层. 3.魔棒工具(调整值 ...
- Java 字符串截取函数 substring()
在String中有两个substring()函数,如下: 一:String.substring(int start) 参数: start:要截取位置的索引 返回: 从start开始到结束的字符串 例如 ...