HDU–1228:A+B (水题)

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。HDU–1228:A+B (水题),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

1. 题目源地址:http://acm.hdu.edu.cn/showproblem.php?pid=1228

2. 源代码:

//HOJ--1228:A+B
#include<iostream>
#include<string>
#include<memory.h>
using namespace std;

int cmp(string a)
{
    if(a=="zero")        return 0;
    else  if(a=="one")   return 1;
    else  if(a=="two")   return 2;
    else  if(a=="three") return 3;
    else  if(a=="four")  return 4;
    else  if(a=="five")  return 5;
    else  if(a=="six")   return 6;
    else  if(a=="seven") return 7;
    else  if(a=="eight") return 8;
    else  if(a=="nine")  return 9;
    else  if(a=="ten")   return 10;    
} 

int main()
{
    int a[2],b[2];
    int i,j,m,n;
    string str;
    
    while(1)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       
       for(i=0; ;i++)//i的值代表数组a中元素个数 
       {
           cin>>str;
           if(str=="+")   
              break;
           else           
              a[i]=cmp(str);
       }
       
       for(j=0; ;j++)//j的值代表数组b中元素个数 
       {
           cin>>str;
           if(str=="=")   
              break;
           else           
              b[j]=cmp(str);
       }
       
       int sum=0;
       int temp=1;
       
       for(m=i-1;m>=0;m--)
       {
          sum=sum+a[m]*temp;
          temp=temp*10;
       }
       
       temp=1; 
       for(n=j-1;n>=0;n--)
       {
          sum=sum+b[n]*temp;
          temp=temp*10;
       }
       
       if(sum)   cout<<sum<<endl;
       else      break;
    }
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/163051.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!