标签:内存 set 输入 0ms change tchar har include problem
求两个大的正整数相减的差。
9999999999999999999999999999999999999 9999999999999
9999999999999999999999990000000000000
思路:
模拟;
来,上代码:
#include<set> #include<map> #include<cmath> #include<stack> #include<queue> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; char s1[221],s2[221]; void exchange() { int l=0,r=strlen(s1)-1; while(r>l) { if(s1[l]>=‘0‘) s1[l]-=‘0‘; if(s1[r]>=‘0‘) s1[r]-=‘0‘; swap(s1[l],s1[r]); l++,r--; } if(l==r) s1[l]-=‘0‘; l=0,r=strlen(s2)-1; while(r>l) { if(s2[l]>=‘0‘) s2[l]-=‘0‘; if(s2[r]>=‘0‘) s2[r]-=‘0‘; swap(s2[l],s2[r]); l++,r--; } if(l==r) s2[l]-=‘0‘; } int main() { cin>>s1; cin>>s2; exchange(); //cout<<s1<<endl<<s2<<endl; for(int i=0;i<=219;i++) { if(s1[i]-s2[i]<0) s1[i+1]--,s1[i]+=10; s1[i]-=s2[i]; } bool if_zero=true; for(int i=219;i>=0;i--) { if(s1[i]==0) continue; if_zero=false; for(int j=i;j>=0;j--) putchar(s1[j]+‘0‘); break; } if(if_zero) putchar(‘0‘); return 0; }
标签:内存 set 输入 0ms change tchar har include problem
原文地址:http://www.cnblogs.com/IUUUUUUUskyyy/p/6131182.html