PAT-乙-1011 1011 A+B 和 C (15 分)
阿新 • • 發佈:2018-12-11
程式碼(java)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i=1; i<=T; i++){ long A = sc.nextLong(); long B = sc.nextLong(); long C = sc.nextLong(); System.out.println("Case #" + i + ": " + (A+B>C?"true":"false")); } } }
程式碼(c++)
#include <iostream> using namespace std; int main(){ int n; cin>>n; for(int i=1; i<=n; i++){ long long int a, b, c; cin>>a>>b>>c; if(a+b>c){ cout<<"Case #"<<i<<": true"<<endl; } else{ cout<<"Case #"<<i<<": false"<<endl; } } return 0; }
註解
主要考察資料範圍。 c++中,需要8個位元組的話要用long long int或者long long。單純的long是不夠的(只有4個位元組)! java中,long佔用8個位元組。