比赛 |
防止浮躁的小练习v0.4 |
评测结果 |
AAAAAA |
题目名称 |
增强的减法问题 |
最终得分 |
100 |
用户昵称 |
kxxy |
运行时间 |
0.002 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-10-13 15:58:56 |
显示代码纯文本
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstdlib>
- #include <cstdio>
- using namespace std;
- string x, y;
- int xx[101]={0}, yy[101]={0}, result[101]={0};
- bool poster=true;
- int maxlength=0;
- int minlength=0;
- inline void compare(string x, string y)
- {
- if (x.length()==y.length())
- {
- maxlength=x.length();
- minlength=y.length();
- if (x>y)
- {
- int j=x.length();
- int k=y.length();
- for (int i=j, q=0; i>0; i--, q++)
- xx[q]=x[i-1]-48;
- for (int i=k, q=0; i>0; i--, q++)
- yy[q]=y[i-1]-48;
- }
- else
- {
- poster=false;
- int j=x.length();
- int k=y.length();
- maxlength=y.length();
- minlength=x.length();
- for (int i=j, q=0; i>0; i--, q++)
- yy[q]=x[i-1]-48;
- for (int i=k, q=0; i>0; i--, q++)
- xx[q]=y[i-1]-48;
- }
- }
- else if (x.length()>y.length())
- {
- int j=x.length();
- int k=y.length();
- maxlength=x.length();
- minlength=y.length();
- for (int i=j, q=0; i>0; i--, q++)
- xx[q]=x[i-1]-48;
- for (int i=k, q=0; i>0; i--, q++)
- yy[q]=y[i-1]-48;
- }
- else if (x.length()<y.length())
- {
- poster=false;
- int j=x.length();
- int k=y.length();
- maxlength=y.length();
- minlength=x.length();
- for (int i=j, q=0; i>0; i--, q++)
- yy[q]=x[i-1]-48;
- for (int i=k, q=0; i>0; i--, q++)
- xx[q]=y[i-1]-48;
- }
- }
- inline void sub()
- {
- for (int i=0; i<maxlength; i++)
- result[i]=xx[i];
- for (int i=0; i<minlength; i++)
- result[i]-=yy[i];
- for (int i=0; i<maxlength-1; i++)
- {
- while (result[i]<0)
- {
- result[i]+=10;
- result[i+1]-=1;
- }
- }
- }
- inline void out_data()
- {
- bool flag=false;
- if (poster==false)
- cout<<"-";
- for (int i=maxlength; i>0; i--)
- {
- if (result[i-1]!=0)
- {
- flag=true;
- cout<<result[i-1];
- }
- else if (result[i-1]==0&&flag==true)
- cout<<0;
- }
- }
- int main()
- {
- freopen("sub.in","r",stdin);
- freopen("sub.out","w",stdout);
- cin>>x>>y;
- compare(x, y);
- if(x==y)
- {
- cout<<0;
- return 0;
- }
- sub();
- out_data();
- return 0;
- }