Little Boxes UVALive - 8209
题意:
给你四个数,输出四个数之和,四个数小于等于262之内
题解:
这。。。这。。水题
unsigned int 0~4294967295 (10位数,4e9)
int -2147483648~2147483647 (10位数,2e9 2^31 - 1)
long long: -9223372036854775808~9223372036854775807 (19位数, 9e18 ) 2^63 - 1
unsigned long long:0~18446744073709551615 (20位数,1e19) 2^64 - 1
代码:
#include <bits/stdc++.h>
using namespace std;
#define asd cout<<" SB "<<endl;
#define ll long long
#define INF 0x3f3f3f3f
int main(){int t;cin>>t;while(t--){ll a,b,c,d;cin>>a>>b>>c>>d;cout<<a+b+c+d<<endl;}return 0;
}
貌似是因为数据太水longlong才能过
大数操作用java
import java.math.BigInteger;
import java.util.Scanner;public class Main {public static Scanner s = new Scanner(System.in);public static void main(String args[]) throws Exception {Scanner in = new Scanner(System.in);int t = in.nextInt();while(t-- != 0) {BigInteger a = in.nextBigInteger();BigInteger b = in.nextBigInteger();BigInteger c = in.nextBigInteger();BigInteger d = in.nextBigInteger();System.out.println(a.add(b.add(c.add(d))));}}
}
c++模拟也可以
#include<iostream>using namespace std;
const int L=110;
string add(string a,string b){string ans;int na[L]={0},nb[L]={0};int la=a.size(),lb=b.size();for(int i=0;i<la;i++){na[la-1-i]=a[i]-'0';}for(int i=0;i<lb;i++){nb[lb-1-i]=b[i]-'0';}int lmax=la>lb?la:lb;for(int i=0;i<lmax;i++) na[i]+=nb[i],na[i+1]+=na[i]/10,na[i]%=10;if(na[lmax]) lmax++;for(int i=lmax-1;i>=0;i--) ans+=na[i]+'0';return ans;
}
string a,b,c,d;
int main(){ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);int T;cin>>T;while(T--){cin>>a>>b>>c>>d;a=add(a,b);c=add(c,d);a=add(a,c);cout<<a<<endl;}return 0;
}