设为首页 加入收藏

TOP

HDU 1047 Integer Inquiry 大数相加 string解法
2015-07-20 17:50:53 来源: 作者: 【 】 浏览:2
Tags:HDU 1047 Integer Inquiry 大数 相加 string 解法

本题就是大数相加,题目都不用看了。

不过注意的就是HDU的肯爹输出,好几次presentation error了。

还有个特殊情况,就是会有空数据的输入case。

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
             using namespace std; void plusABtoA(string &a, string &b) { string c; int n = (int)a.size(), m = (int)b.size(), carry = 0; for (int i = n-1, j = m-1; i >= 0 || j >= 0 || carry; i--, j--) { int an = i>=0? a[i]-'0' : 0; int bn = j>=0? b[j]-'0' : 0; carry = an+bn+carry; c += char(carry%10 + '0'); carry /= 10; } reverse(c.begin(), c.end()); a = c; } int main() { int N; string a, b; cin>>N; while (N--) { cin>>a; if (a == "0")//注意特殊情况 { cout<
               continue; } while (cin>>b && b != "0") { plusABtoA(a, b); } cout<
              
               


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2014多校10(1001)hdu4971(强连.. 下一篇UVA - 11645 Bits

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·switch520最新的地址 (2025-12-24 19:19:41)
·微信聊天功能使用了 (2025-12-24 19:19:39)
·websocket和普通的so (2025-12-24 19:19:36)
·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)