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 ...
随机推荐
- Oracle_用户管理
创建用户: CREATE USER user --创建用户user IDENTIFIED {BY password | EXTERNALLY} --设备用户密码,EXTERNALLY说用该用户由 ...
- [LeetCode][Python]14: Longest Common Prefix
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- javascript数组顺序-----1冒泡的另一种比较好理解的写法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ubuntu14.04 Markdown编辑器推荐之Remarkable
如今已经习惯了用Markdown编辑器写博文的习惯,那么ubuntu以下有什么好用的呢?搜索中发现了这个叫Remarkable的免费Markdown编辑器.为什么推荐这个呢?说说它的特点: 实时预览 ...
- C# SQL文件执行器的功能实现
好一段时间没写博客了,这次我们来一起谈谈SQL文件执行器的功能实现,在ERP软件升级时往往在客户端程序更新的同时也要对数据库进行升级,ERP程序开发人员会对数据库升级的执行代码在开发的过程中以SQL文 ...
- Java单态模式
Java的单态模式 Singletom 作用:保证在Java应用程序中,一个Java类只有一个实例存在:所以一般单态类会提供一个返回该类实例的方法.提供一个对对象的全局访问指针. 优点:节省内存,限制 ...
- 什么时候css会见less
在一定程度上,css不能被视为一个节目.虽然和其他语言,它有自己的规范.编码,但它的笨拙实在让我失望. 不喜欢css是由于不管怎么优化代码.项目大到一定程序后.都会看上去一团乱.并且有时候一个bug的 ...
- AIDL 发生异常的原因 Android java.lang.SecurityException: Binder invocation to an incorrect interface
我建立了两个project.一个是activity 的 ,一个是service 的. 在进行两个project通信时,应该有以下几点注意: 1.在activity project中引入service ...
- gridview合并相同的行
#region 方法:合并Gridview行 /// <summary> /// 合并GridView指定行单元格 /// </summary> /// ...
- smarty函数-转载
Smarty常用函数 2009-08-13 14:05:55| 分类: Php |举报 |字号 订阅 1 .include_once语句: 引用文件路径,路径必需正确. eg:include ...