Description
定义两个长度相同的数字之间的运算
|−|
,
A|−|B
的第
i
位是
Input
两个整数 A,B(0≤A,B≤109) ,保证两个数字位数相同
Output
输出 A|−|B 的值,不带前导零
Sample Input
123 151
Sample Output
32
Solution
水题,按要求模拟即可
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int n,x,a[11],b[11],c[11];
int main()
{
while(~scanf("%d",&x))
{
n=0;
while(x)
{
a[++n]=x%10,x/=10;
}
scanf("%d",&x);
n=0;
while(x)
{
b[++n]=x%10,x/=10;
}
for(int i=1;i<=n;i++)a[i]=abs(a[i]-b[i]);
while(n&&a[n]==0)n--;
if(n==0)a[++n]=0;
for(int i=n;i;i--)printf("%d",a[i]);
printf("\n");
}
return 0;
}