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. discuz函数quote

    public static function quote($str, $noarray = false) { if (is_string($str)) return '\'' . addcslashe ...

  2. js原生forEach、map与jquery的each、$.each的区别

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  3. 安装python模块

    要想在python中使用import的一些模块,前提是要安装这些模块. 可以使用pip来导入模块. 打开终端,输入命令: sudo easy_install pip 安装好pip后,就可以使用pip来 ...

  4. hive集群安装配置

    hive 是JAVA写的的一个数据仓库,依赖hadoop.没有安装hadoop的,请参考http://blog.csdn.net/lovemelovemycode/article/details/91 ...

  5. ASP.NET MVC4 ASP.NET Web API路由规则

    using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Web.Ht ...

  6. SQL 常用基础语句

    1.SQL SELECT 语句 语法:SELECT    列名称    FROM    表名称 2.SQL SELECT DISTINCT 语句 语法:SELECT    DISTINCT    列名 ...

  7. 3.一步一步学c#(三):对象和类型

    类和结构 类和结构实际上都是创建对象的模板,每个对象都包含数据,并提供了处理和访问数据的方法,. 结构与类的区别是它们在内存中的存储方式,访问方式(类是存储在堆(heap)上的引用类型),而结构是存储 ...

  8. The Rose

    Some say love it is a river 有人说爱是一条河 that drowns the tender reed 会淹没轻柔的芦苇 Some say love it is a razo ...

  9. intellj idea 如何设置类头注释和方法注释

    intellj idea 如何设置类头注释和方法注释           intellj idea的强大之处就不多说了,相信每个用过它的人都会体会到,但是我们也会被他的复杂搞的晕头转向,尤其刚从ecl ...

  10. jQ的自定义插件

    此文运用的是优雅的Markdown而书 项目中写js时,有很多时候有需要重复利用的东西,我们可以给它们写成一个插件的形式,这样阅读性和适用性都会大大提高.最近抽个时间,好一番的研究了下 Jcrop 的 ...