(File IO): input:score.in output:score.out
時間限制: 1000 ms 空間限制: 262144 KB 具體限制
Goto ProblemSet
題目描述
進入初中後,覺得自己不能總是玩兒了,應該要好好學習了。正好一次考試結束了,想知道自己的語文,數學,英語分別與語文年級第一,數學年級第一,英語年級第一相差多少。由於所在年級有個人,所以想你編個程序幫幫他。
輸入
共行,第一~三行分別爲的語文數學英語成績(位數),第四行爲,以下行,每行一個數(它們的位數是),分別爲第個同學的語文,數學,英語成績。
即:的語文
的數學
的英語
第一個人的語文
數學
英語
第二個人的語文
…
輸出
共一行,有三個數,分別爲的語文數學英語與年級第一的差。
如果是第一,則輸出.
樣例輸入
10
10
10
3
0
80
0
40
0
0
0
0
100
樣例輸出
30 70 90
數據範圍限制
對於%的數據,.
對於%的數據,.且都爲整數。
解題思路
高精度
代碼
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
string a,b,c,d,e,f,a1,b1,c1;
int n,l1,l2,l3,s1[70],s2[70],s3[70];
string maxn(string x,string y){
int l1=x.size(),l2=y.size();
if(l1==l2)
{
if(x<y)
return y;
else
return x;
}
else if(l1<l2)
return y;
else
return x;
}
void sub(string x,string y){
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
memset(s3,0,sizeof(s3));
l1=x.size();
l2=y.size();
if(l1>l2||(l1==l2&&x>y))
{
for(int i=l1-1;i>=0;i--)
s1[l1-i-1]=x[i]-'0';
for(int i=l2-1;i>=0;i--)
s2[l2-i-1]=y[i]-'0';
l3=l1;
for(int i=0;i<l3;i++)
{
s3[i]+=(s1[i]-s2[i]);
if(s3[i]<0)
{
s3[i]+=10;
s3[i+1]--;
}
}
while(s3[l3]==0)
l3--;
}
else
{
s3[0]=0;
len=0;
}
}
int main(){
freopen("score.in","r",stdin);
freopen("score.out","w",stdout);
cin>>a>>b>>c;
a1=a;
b1=b;
c1=c;
scanf("%d",&n);
while(n--)
{
cin>>d>>e>>f;
a1=maxn(a1,d);
b1=maxn(b1,e);
c1=maxn(c1,f);
}
sub(a1,a);
for(int i=l3;i>=0;i--)
cout<<s3[i];
cout<<" ";
sub(b1,b);
for(int i=l3;i>=0;i--)
cout<<s3[i];
cout<<" ";
sub(c1,c);
for(int i=l3;i>=0;i--)
cout<<s3[i];
cout<<endl;
return 0;
}