1002
来源:互联网 发布:腾讯大数据分析平台 编辑:程序博客网 时间:2024/06/10 21:39
class LargeNumber{char A[1001];int Length;public:LargeNumber(){memset(A,'0',sizeof(A));}void Input();void Output();void OutputOnScreen();friend LargeNumber Add(LargeNumber x,LargeNumber y);};void LargeNumber::OutputOnScreen(){for(int i=Length-1;i>=0;i--)cout<<A[i];}void LargeNumber::Input(){int i=0;char c;while(c=getchar()){if(c==' '||c=='\n')break;A[i]=c;i++;}Length=i;int a=0;int b=Length-1;while(a<b){char v;v=A[a];A[a]=A[b];A[b]=v;a++;b--;}}void LargeNumber::Output(){for(int i=0;i<Length;i++)cout<<A[i];}LargeNumber Add(LargeNumber x,LargeNumber y){LargeNumber l;for(int i=0;i<max(x.Length,y.Length);i++)l.A[i]=x.A[i]-'0'+y.A[i];for(int i=0;i<max(x.Length,y.Length)+1;i++)if(l.A[i]>'9'){l.A[i]=l.A[i]-10;l.A[i+1]=l.A[i+1]+1;}if(l.A[max(x.Length,y.Length)]=='0')l.Length=max(x.Length,y.Length);elsel.Length=max(x.Length,y.Length)+1;return l; }
Compilation Error 两次<我用了max,不得已自己又写了一遍>
WA了三次<case 小写了>
还有两次Presentation Error<回车格式没放对。。我现在都没懂>
这题主要考了LargeNumber,我刚开始用int没通过,又用了double转int,和longlong都没过。
数据来源:http://www.cnblogs.com/xiangshancuizhu/archive/2010/12/12/1903719.html
数据来源:http://blog.csdn.net/xuexiacm/article/details/8122267
【无意剽窃别人成果,就是个人当笔记】
而我发现题目上有 "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."
还有一个小收获:以前见过没注意
meset函数:
memset(A,'0',sizeof(A));
0 0
- 1002 。
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- 1002
- JAVA_WEB经典面试题
- 内置着色器包含文件
- OpenGL ES 2.0 正交投影和透视投影
- Unity3D工程版本管理方案
- Jenkins进阶系列之——04Publish Over FTP Plugin插件
- 1002
- OnEnable, Awake, Start order
- Jenkins进阶系列之——05FTP publisher plugin插件
- Unity ScriptObject
- windows 下配置SVN 服务端、客户端
- SVN来管理Unity3d工程
- access_log 字段解释
- MySQL数据库之多表操作
- Jenkins进阶系列之——06FTP publisher plugin插件下载(支持绝对路径)