hdu 1228 A + B
生活随笔
收集整理的這篇文章主要介紹了
hdu 1228 A + B
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Problem Description
讀入兩個小于100的正整數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
讀入兩個小于100的正整數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 <string> #include <stdio.h> #include <algorithm> #include <cmath> #include <cstring> #include <iomanip> using namespace std; int cmp(string st,int a) {if(st=="zero") a=a*10+0;else if(st=="one") a=a*10+1;else if(st=="two") a=a*10+2;else if(st=="three") a=a*10+3;else if(st=="four") a=a*10+4;else if(st=="five") a=a*10+5;else if(st=="six") a=a*10+6;else if(st=="seven") a=a*10+7;else if(st=="eight") a=a*10+8;else if(st=="nine") a=a*10+9;return a; } int main() {string st;int n,m,k;while(cin>>st){ n=0;m=0;k=0;n=cmp(st,n);while(cin>>st){if(st!="+"&&k==0)n=cmp(st,n);else if(st=="+")k=1;else if(k==1&&st!="=")m=cmp(st,m);else if(st=="=") break;}if(n==0&&m==0) break;else cout<<n+m<<endl;}return 0; }轉載于:https://www.cnblogs.com/wangyumin/p/5323492.html
總結
以上是生活随笔為你收集整理的hdu 1228 A + B的全部內容,希望文章能夠幫你解決所遇到的問題。