ZOJ Problem Set - 3492||Kagome Kagome

Kagome Kagome

Time Limit: 2 Seconds       Memory Limit: 65536 KB

Kagome kagome, kago no naka no tori wa
Itsu itsu deyaru? Yoake no ban ni
Tsuru to kame to subetta.
Ushiro no shoumen daare?
Translation:
Kagome kagome, the bird in the cage,
when will you come out?
In the evening of the dawn,
the crane and turtle slipped.
Who stands right behind you now?

Kagome Kagome is a Japanese children's game. One child is chosen as the oni (literally demon or ogre, but similar to the concept of "it" in tag) and sits blindfolded (or with their eyes covered). The other children join hands and walk in circles around the oni while singing the song for the game. When the song stops, the oni speaks aloud the name of the person behind him, and if he is correct, the person behind will exchange places with the oni.

Higurashi Tewi is playing Kagome Kagome with her n (n is even) friends as the oni now. She peeps to know who is right in front of her. Knowing the order of the children in circle and assuming that they keep distance evenly, it's easy to derive who is right behind her.

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

The first line of each test case starts with an even number 1 ≤ n ≤ 100, followed by the name of the child who is right in front of Higurashi Tewi. The second line contains exactly ndifferent names, listed in counterclockwise order. Name is an alphanumeric string whose length never exceeds 20. It's guaranteed that the child in front of Higurashi Tewi is always contained in the list exactly once.

Output

For each test case, output the name of the child who is right behind Higurashi Tewi.

Sample Input
3
2 Alice
Alice Bob
4 inu
inu neko usagi kizune
4 cat
dog cat rabbit fox
Sample Output
Bob
usagi
fox
References


题目的大意就好比是小时候玩的,丢手绢游戏一样,几个小伙伴坐在一起,有一个人坐着根据对面是谁来猜出后面的人是谁。可以推出人数肯定是偶数个人数。


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, i,j;
		char name[105][25];
		scanf("%d %s", &n, name[0]);
		for (i = 1; i <= n; i++)
			scanf("%s", name[i]);
		for (i = 1; i <= n; i++)
		{
			if (strcmp(name[0], name[i]) == 0)
				break;
		}
		if (i <= n / 2)
			j = i + n / 2;
		else
			j = (i + n/2) % n;
		printf("%s\n", name[j]);
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值