题解:P14100 [ZJCPC 2017] Cooking Competition
yuhaotian000 · · 题解
题解:P14100 [ZJCPC 2017] Cooking Competition
一道小模拟题。
题目大意
本题没有中文翻译,所以我来形式化的说一下。这道题的意思就是有两人比赛厨艺,对于每个测试样例组,请了
问最后谁的分数更高。
题目解法
这道题只需要对于每个人的回答,给两人的分数进行加减即可。使用分支结构来判断回答种类。
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int k=0,t=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x==1){ // 第一种
k++;
}else if(x==2){ // 第二种
t++;
}else if(x==3){ // 第三种
k++,t++;
}else{ // 第四种
k--,t--;
}
}
if(k>t){
cout<<"Kobayashi";
}else if(k<t){
cout<<"Tohru";
}else{
cout<<"Draw";
}
cout<<endl;
}
}
这个代码是可以过的,但是我们注意到当回答为第三种或第四种时,两人之间的比分差没有任何区别,所以我们就可以不判断第三种和第四种了。
AC code
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int k=0,t=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x==1){ // 第一种
k++;
}else if(x==2){ // 第二种
t++;
}
/*
else if(x==3){ // 第三种
k++,t++;
}else{ // 第四种
k--,t--;
}
*/
}
if(k>t){
cout<<"Kobayashi";
}else if(k<t){
cout<<"Tohru";
}else{
cout<<"Draw";
}
cout<<endl;
}
}