A+B Coming 解题报告

http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1563

A+B Coming

Time Limit: 1 Sec   Memory Limit: 125 MB
Submissions: 32   Solved: 15
[ Submit][ Status][ Discuss]

Description

Many classmates said to me that A+B is must needs. If you can’t AC this problem, you would invite me for night meal. ^_^

Input

Input may contain multiple test cases. Each case contains A and B in one line. A, B are hexadecimal number. Input terminates by EOF.

Output

Output A+B in decimal number in one line.

Sample Input

1 9
A B
a b

Sample Output

10
21
21

代码:

Code:
  1. #include <iostream>    
  2. using namespace std;    
  3.        
  4. int a,b;     
  5.        
  6. int main(){     
  7.     while(cin>>hex>>a>>b)    
  8.         cout<<dec<<a+b<<endl;    
  9.     return 0;     
  10. }     
  11. /**************************************************************   
  12.     Problem: 1563   
  13.     User: mmoaay   
  14.     Language: C++   
  15.     Result: Accepted   
  16.     Time:0 ms   
  17.     Memory:1352 kb   
  18. ****************************************************************/  

刚开始的时候自己写的16进制转10进制,结果无耻地错了,然后更无耻的是:原来如此简单……

有必要总结一下c++输入输出数的进制问题: 

dec-十进制(默认)

oct-八进制

hex-十六进制

在cin和cout中指明相应的数据形式。

例:

Code:
  1. int i,j,k,l;   
  2. cout<<"Input i(oct) j(hex) k(hex) l(dec):"<<endl;   
  3. cin>>oct>>i;                                            //输入为八进制数   
  4. cin>>hex>>j;                                            //输入为十六进制数   
  5. cin>>k;                                                 //输入仍为十六进制数   
  6. cin>>dec>>l;                                            //输入为十进制数   
  7. cout<<"hex:"<<"i="<<hex<<i<<endl;   
  8. cout<<"dec:"<<"j="<<dec<<j<<'/t'<<"k="<<k<<endl;   
  9. cout<<"oct:"<<"l="<<oct<<l;   
  10. cout<<dec<<endl;                                        //恢复十进制输出状态  

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

T技术沙龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值