P7369 [COCI2018-2019#4] Elder
题目链接:https://www.luogu.com.cn/problem/P7369
思路:
每次输入巫师决斗时,先判断当前老魔杖所效忠的巫师有无参与决斗
若参与决斗,那么老魔杖换人效忠;若无,不换人
同时,注意之前效忠过的巫师可能会再次效忠。所以用一个数组进行记录,新效忠的巫师之前是否效忠过
代码如下:
#include
#include
#include using namespace std;int main ( )
{char x, y, z, ans[ 91 ];int n, sum = 1;cin >> x >> n;memset ( ans, 0, sizeof ( ans ) );ans[ x ] = 1;while ( n -- ){cin >> y >> z;if ( z == x ){x = y;if ( !ans[ y ] ){ans[ y ] = 1;++ sum;}}}cout << x << endl;cout << sum << endl;return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
