“Miss Kobayashi’s Dragon Maid” is a Japanese manga series written and illustrated by Coolkyoushinja. An anime television series produced by Kyoto Animation aired in Japan between January and April 2017.
In episode 8, two main characters, Kobayashi and Tohru, challenged each other to a cook-off to decide who would make a lunchbox for Kanna’s field trip. In order to decide who is the winner, they asked n people to taste their food, and changed their scores according to the feedback given by those people.
There are only four types of feedback. The types of feedback and the changes of score are given in the following table.
Type | Feedback | Score Change(Kobayashi) | Score Change(Tohru) |
---|---|---|---|
1 | Kobayashi cooks better | +1 | 0 |
2 | Tohru cooks better | 0 | +1 |
3 | Both of them are good at cooking | +1 | +1 |
4 | Both of them are bad at cooking | -1 | -1 |
Given the types of the feedback of these n people, can you find out the winner of the cooking competition (given that the initial score of Kobayashi and Tohru are both 0)?
解题思路
简单模拟
- a[i] = 1, Kobayashi +1
- a[i] = 2, Tohru + 1
- a[i] = 3, Kobayashi and Tohru +1
- a[i] = 4, Kobayashi and Tohru -1
判断两人分数谁高,或者平局 Draw
。
代码
#include<bits/stdc++.h>
using namespace std;
int a[22];
int main()
{
int T, n;
scanf("%d",&T);
while(T-- && scanf("%d",&n))
{
int tohru = 0, kobayashi = 0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]&1) kobayashi++;
if(a[i]&2) tohru++;
if(a[i]==4) tohru--, kobayashi--;
}
if(tohru == kobayashi) printf("Draw\n");
else if(kobayashi > tohru) printf("Kobayashi\n");
else printf("Tohru\n");
}
}