题目网址:点击进入
problem:
Little boxes on the hillside.
Little boxes made of ticky-tacky.
Little boxes.
Little boxes.
Little boxes all the same.
There are a green boxes, and b pink boxes.
And c blue boxes and d yellow boxes.
And they are all made out of ticky-tacky.
And they all look just the same.
Input:
The input has several test cases. The first line contains the integer t (1 ≤ t ≤ 10) which is the total number of test cases.
For each test case, a line contains four non-negative integers a, b, c and d where a, b, c, d ≤ 2^62, indicating the numbers of green boxes, pink boxes, blue boxes and yellow boxes.
Output:
For each test case, output a line with the total number of boxes.
Sample Input:
4
1 2 3 4
0 0 0 0
1 0 0 0
111 222 333 404
Sample Output:
10
0
1
1070
大致题意:
输入t组数据每组数据四个数,求和
思路:眼看是水题,再看看数据范围如果极限的话结果和爆范围了,所以需要处理一下数字,或许用模拟高精度加法也可以
代码:
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
int t;
cin>>t;
while (t--)
{
ll a,b,c,d;
cin>>a>>b>>c>>d;///极限数据下-1使得范围在ll里面,把个位拿出来单独输出
if (a==(1ll<<62)&&b==(1ll<<62)&&c==(1ll<<62)&&d==(1ll<<62))
cout<<(a-1+b+c+d)/10<<(a-1+b+c+d)%10+1<<endl;
else
cout<<a+b+c+d<<endl;
}
return 0;
}
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long LLD;
LLD sum[1005];///总和
char a[1005],b[1005],c[1005],d[1005];///四个数字字符串输入
int main()
{
LLD t,length,MAX=0,first;///t组,数字长度,四个数字最长,反序指针标记
scanf("%lld%*c",&t);
while (t--)
{
memset(a,0,sizeof(a));///所有全部归0
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(d,0,sizeof(d));
memset(sum,0,sizeof(sum));
scanf("%s%*c%s%*c%s%*c%s%*c",&a,&b,&c,&d);
length=strlen(a),first=0;
for (LLD i=length-1;i>=0;i--)
{
sum[first]=sum[first]+(a[i]-'0');///从末尾个位数开始相加
if (sum[first]>=10)
{
sum[first]=sum[first]%10;///大于10就进位处理
sum[first+1]++;
}
first++;
}
MAX=max(MAX,first);///计算最大长度
length=strlen(b),first=0;
for (LLD i=length-1;i>=0;i--)
{
sum[first]=sum[first]+(b[i]-'0');
if (sum[first]>=10)
{
sum[first]=sum[first]%10;
sum[first+1]++;
}
first++;
}
MAX=max(MAX,first);
length=strlen(c),first=0;
for (LLD i=length-1;i>=0;i--)
{
sum[first]=sum[first]+(c[i]-'0');
if (sum[first]>=10)
{
sum[first]=sum[first]%10;
sum[first+1]++;
}
first++;
}
MAX=max(MAX,first);
length=strlen(d),first=0;
for (LLD i=length-1;i>=0;i--)
{
sum[first]=sum[first]+(d[i]-'0');
if (sum[first]>=10)
{
sum[first]=sum[first]%10;
sum[first+1]++;
}
first++;
}
MAX=max(MAX,first);///如果最高位数0的话就-1防止出现0122开头0的结果
if (sum[MAX]==0)
{
MAX--;
}
for (LLD i=MAX;i>=0;i--)///从最高位输出
{
printf("%d",sum[i]);
}
printf("\n");
}
return 0;
}