例题3_4 猜数字游戏的提示(UVa340)

实现一个经典“猜数字”游戏。给定答案序列和用户猜的序列,统计有多少数字位置正确(A),有多少数字在两个序列都出现过但位置不对(B)。

输入包含多组数据。每组输入第一行为序列长度n,第二行是答案序列,接下来是若干猜测序列。猜测序列全0时该组数据结束。n=0时输入结束。

样例输入:

4

1 3 5 5

1 1 2 3

4 3 3 5

6 5 5 1

6 1 3 5

1 3 5 5

0 0 0 0

10

1 2 2 2 4 5 6 6 6 9

1 2 3 4 5 6 7 8 9 1

1 1 2 2 3 3 4 4 5 5

1 2 1 3 1 5 1 6 1 9

1 2 2 5 5 5 6 6 6 7

0 0 0 0 0 0 0 0 0 0

0

样例输出:

Game 1:

(1,1)

(2,0)

(1,2)

(1,2)

(4,0)

Game 2:

(2,4)

(3,2)

(5,0)

(7,0)

时间: 2025-01-12 15:27:01

例题3_4 猜数字游戏的提示(UVa340)的相关文章

猜数字游戏的提示(Master-Mind Hints,UVa340)

[本博文非博主原创,思路与题目均摘自 刘汝佳<算法竞赛与入门经典(第2版)>] Question 例题3-4 猜数字游戏的提示(Master-Mind Hints,UVa340) 实现一个经典的"猜数字"游戏.给定答案序列和用户猜的序列,统计有多少数字位置正确(A),有多少数字在两个序列都出现过但位置不对(B). 输入包含多组数据.每组输入第一行为序列长度 n,第二行是答案序列,接下来若干行猜测序列.猜测序列全0 时该组数据结束. n=0时输入结束. Example Inp

UVa 340 Master-Mind Hints(猜数字游戏的提示)

题意  猜数字游戏  统计猜的数字有多少个数字位置正确  有多少个数字在答案中出现但是位置不正确  每个字符只能匹配一次 直接匹配每位数 #include<cstdio> #include<algorithm> #include<map> using namespace std; const int N = 1005; int a[N], b[N], c, d; int main() { int n, cas = 0; while (scanf ("%d&qu

猜数字游戏的提示 (Master-Mind Hints, UVa 340)

题目: 实现一个经典"猜数字"游戏. 给定答案序列和用户猜的序列,统计有多少数字位置正确(A),有多少数字在两个序列都出现过但位置不对(B). 输入包含多组数据. 每组输入第一行为序列长度n,第二行是答案序列,接下来是若干猜测序列. 猜测序列全0时该组数据结束. n=0时输入结束. 样例输入:4 13 5 51 1 2 34 3 3 56 5 5 16 1 3 51 3 5 50 0 0 0101 2 2 2 4 5 6 6 6 91 2 3 4 5 6 7 8 9 11 1 2 2

猜数字游戏的提示(Master-Mind Hints , UVa 340)

MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N that a code must

猜数字游戏的提示

题目来自刘汝佳编著的<算法竞赛入门经典(第二版)> 题目描述: 我的代码: #include<iostream> #include<cstring> using namespace std; int main() { int answer[100]; int copy[100]; int enter[100]; int n, a, b; int count = 0; n = 1; while (n != 0) { cin >> n; for (int i =

编程成长日记————猜数字游戏

模拟猜数字游戏,提示用户每次应输入的数字范围. #include <stdio.h> #include <stdlib.h> //猜数字游戏 int main() { int i=0; int num =0,ret=0,choose=0; int min=1,max=100; flag: srand((unsigned)time(NULL));  ret=rand()%100+1; while(1) { printf("请输入%d~%d之间的数字:\n",min

算法习题---3.01猜数字游戏提示

一.题目 实现一个经典“猜数字”游戏.给定答案序列和用户猜的序列,统计有多少数字位置正确(A),有多少数字在两个序列都出现过但位置不对(B). 输入包含多组数据.每组输入第一行为序列长度n,第二行是答案序列,接下来是若干猜测序列,猜测序列全0时该组数据结束.n=0时输入结束. 二:样例输入: 4 //列数 1 3 5 5 //答案序列 1 1 2 3 //猜测序列--下面都是--直到结束序列 4 3 3 5 6 5 5 1 6 1 3 5 1 3 5 5 0 0 0 0 //结束序列 10 //

JavaScript一个猜数字游戏

效果图: 代码: <body> <script type="text/javascript"> window.onload = newgame; //页面载入的时候就开始一个新的游戏 window.onpopstate = popState; //处理历史记录相关事件 var state,ui; //全局变量,在newgame()方法中会对其初始化 function newgame( playagin ){ //开始一个新的猜数字游戏 //初始化一个包含需要的文

Python实现简单的猜数字游戏

Python实现简单的猜数字游戏,具体如下: 随机生成一个1-10之间的数字,让用户来猜,当猜错时,会提示猜的数字是大还是小了,直到用户猜对为止. import random secret = random.randint(1,10) #print(secret) print('------猜数字游戏!-----') guess = 0 while guess != secret: temp = input('猜数字游戏开始,请输入数字:') guess = int(temp) if guess