A + B Problem II
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
代码 如下,为了 省事 ,我用C#写的控制台 程序,并且考虑有点 不太周全 ,只考虑到了A数字长度 大于等于B数字的情况。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | using System; using System.Text; namespace TestSum { class Program { static void Main( string [] args) { long a = 112233445566778899; long b = 998877665544332211; //long a = 123; //long b = 29; char [] ac = a.ToString().ToCharArray(); char [] bc = b.ToString().ToCharArray(); StringBuilder result = new StringBuilder(); if (ac.Length>=bc.Length) { int temp = 0; for ( int i = ac.Length - 1, j = bc.Length-1; i>=0; i--,j--) { int indexValue = 0; if (temp == 1) { indexValue++; } int _a = 0, _b = 0; if (j<0) { _b = 0; _a = int .Parse(ac[i].ToString()); } else { _a = int .Parse(ac[i].ToString()); _b = int .Parse(bc[j].ToString()); } if (_a+_b>9) { indexValue+= ((_a + _b-10 )); temp = 1; } else { indexValue+= (_a + _b); temp = 0; } result.Append(indexValue); } } reverse(result.ToString()); Console.ReadKey(); } static void reverse( string result) { for ( int i =result.Length-1;i>=0;i--) { Console.Write(result[i]); } } } } |
__EOF__
作 者:ღKawaii
出 处:https://www.cnblogs.com/kmsfan/p/7471405.html
关于博主:一个普通的小码农,为了梦想奋斗
版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本。
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!

作者:
KMSFan
出处:http://www.cnblogs.com/kmsfan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
欢迎大家加入KMSFan之家,以及访问我的优酷空间!
出处:http://www.cnblogs.com/kmsfan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
欢迎大家加入KMSFan之家,以及访问我的优酷空间!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
2015-09-03 算法导论 - 函数的增长。