Problem ID :a039. 公平的戰役(EOF版)

New Thread

User 抓不到問題,解題時跑出多輸出一行,為什麼呢

kuan SendIMessage
3lohsa

a039. 公平的戰役(EOF版) | From: 114.41.91.236 | Post Date:2021-05-24 10:02:04.0

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int a,b,c,d,n,i,x,y;
while(1){
if (cin.fail()){
break;
}
cin>>a>>b;
if (a>b){
cout<<"A"<<" "<<a-b;
}
else if (b>a){
cout<<"B"<<" "<<b-a;
}
else {
cout<<"0";
}
cout<<"\n";
}
return 0;
}
 


文章類型: 一般 | Reply | Back
User Re:抓不到問題,解題時跑出多輸出一行,為什麼呢

tibitTW SendIMessage
tibitTW

a039. 公平的戰役(EOF版) | From: 42.77.32.250 | Post Date:2021-05-24 13:43:52.0

#include
#include
#include
using namespace std;
int main(){
int a,b,c,d,n,i,x,y;
while(1){
if (cin.fail()){
break;
}
cin>>a>>b;
if (a>b){
cout<<"A"<<" "<
}
else if (b>a){
cout<<"B"<<" "<
}
else {
cout<<"0";
}
cout<<"\n";
}
return 0;
}

你的 cout << "\n"; 每次輸出後都必定會執行,所以程式結束時會多輸出一個換行字元
 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum