PAT(Basic Level):A+B和C
阿新 • • 發佈:2019-02-11
一、給定區間[-2的31次方, 2的31次方]內的3個整數A、B和C,請判斷A+B是否大於C。
很基礎一道題,考察最基本的資料結構,一個簡單的long型的陣列即可解決,沒有必要動用集合。
#include<iostream> using namespace std; int main() { int i = 0; int t = 0; scanf("%d",&t); long int a,b,c; int arraySize = t*3; long int array[arraySize]; int q = 0; while(i<arraySize) { cin>>array[i++]; } for(i=0; i<arraySize; i+=3) { q++; a = array[i]; b = array[i+1]; c = array[i+2]; if(a+b>c) { cout<<"Case #"<<q<<": true"<<endl; } else { cout<<"Case #"<<q<<": false"<<endl; } } return 0; }