当前位置:网站首页>Simple continuous viewing PTA
Simple continuous viewing PTA
2022-07-06 20:38:00 【Sophomore to major】
Interesting topic , There are many input pits in front , Just pay attention .
This problem requires the realization of a simple game simulation program .
Given a 2N×2N Square grid game panel , Place some symbols in each grid . These symbols must appear in pairs , There may be more than one pair of the same symbol . The program reads in a pair of positions given by the player (x1,y1)、(x2,y2), Judge whether the symbols in these two positions match . If the match is successful , Then eliminate the two symbols to “*” And output the erased disk surface ; Otherwise output “Uh-oh”. If the matching error reaches 3 Time , The output “Game Over” And end the game . Or when all symbols match successfully , The output “Congratulations!”, And end the game .
Input format :
Enter a positive integer on a line N(<5). And then 2N That's ok , Each row 2N Capital letters ( In the meantime 1 Space separation ), Indicates the game disk . A positive integer is given after the disk surface K, And then K That's ok , Each line follows the format “x1 y1 x2 y2” Give a player's input . Pay attention to the lines in the grid 、 Column number is from 1 To 2N.
Output format :
According to each step of the player, enter , Output the corresponding result . When outputting the disk surface, pay attention to , The characters in each line are separated by 1 Space separation , There must be no extra space at the end of the line .
sample input 1:
2
I T I T
Y T I A
T A T Y
I K K T
11
1 1 1 3
4 2 4 3
3 1 4 2
2 2 1 2
3 1 2 4
4 4 3 1
2 1 3 4
3 3 1 4
4 1 2 3
2 4 3 2
1 1 2 2
sample output 1:
* T * T
Y T I A
T A T Y
I K K T
* T * T
Y T I A
T A T Y
I * * T
Uh-oh
* * * T
Y * I A
T A T Y
I * * T
Uh-oh
* * * T
Y * I A
* A T Y
I * * *
* * * T
* * I A
* A T *
I * * *
* * * *
* * I A
* A * *
I * * *
* * * *
* * * A
* A * *
* * * *
Congratulations!
sample input 2:
2
I T I T
Y T I A
T A T Y
I K K T
5
1 1 4 4
1 1 2 3
1 1 2 3
2 2 4 1
2 2 3 3
sample output 2:
Uh-oh
* T I T
Y T * A
T A T Y
I K K T
Uh-oh
Uh-oh
Game Over
#include <stdio.h>
int main() {
int n;
char arr[100][100];
scanf("%d", &n);
getchar();//\n
for (int i = 0; i < 2 * n; i++) {// Be careful with this input
scanf("%c", &arr[i][0]);
for (int j = 1; j < 2 * n; j++) {
scanf(" %c", &arr[i][j]);
}
getchar();
}
int k, x1, y1, x2, y2;
scanf("%d", &k);
int flag = 1, ctn = 0, flag2;//flag Judge first ,flag2 Judge whether it is finished
for (int i = 0; i < k; i++) {
flag2=0;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
if (arr[x1 - 1][y1 - 1] == arr[x2 - 1][y2 - 1]&&arr[x1-1][y1-1]!='*'&&arr[x2-1][y2-1]!='*') {
arr[x1 - 1][y1 - 1] = arr[x2 - 1][y2 - 1] = '*';
}
else {
ctn++;
printf("Uh-oh\n");
if (ctn == 3) { printf("Game Over"); break; }
continue;
}
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < 2 * n; j++) {
if (arr[i][j] != '*') {
flag2 = 1; break;
}
}
}
if (flag2 == 0) {
printf("Congratulations!");
break;
}
if (flag2) {
for (int i = 0; i < 2 * n; i++) {
flag = 1;
for (int j = 0; j < 2 * n; j++) {
if (flag) { flag = 0; printf("%c", arr[i][j]); }
else {
printf(" %c", arr[i][j]);
}
}
printf("\n");
}
}
}
return 0;
}
边栏推荐
- 强化学习-学习笔记5 | AlphaGo
- JS implementation force deduction 71 question simplified path
- Tencent T4 architect, Android interview Foundation
- Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
- Case ① | host security construction: best practice of 3 levels and 11 capabilities
- Wechat applet common collection
- 【微信小程序】运行机制和更新机制
- JVM_ Common [interview questions]
- Web security - payload
- What key progress has been made in deep learning in 2021?
猜你喜欢
【DSP】【第二篇】了解C6678和创建工程
[weekly pit] calculate the sum of primes within 100 + [answer] output triangle
The mail command is used in combination with the pipeline command statement
报错分析~csdn反弹shell报错
Event center parameter transfer, peer component value transfer method, brother component value transfer
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
APS taps home appliance industry into new growth points
随机推荐
Leetcode hot topic Hot 100 day 32: "minimum coverage substring"
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
Mécanisme de fonctionnement et de mise à jour de [Widget Wechat]
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
(工作记录)2020年3月11日至2021年3月15日
[cloud native and 5g] micro services support 5g core network
棋盘左上角到右下角方案数(2)
Rhcsa Road
Rhcsa Road
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third
自定义限流注解
Utilisation de l'écran OLED
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
2022 nurse (primary) examination questions and new nurse (primary) examination questions
01 basic introduction - concept nouns
2110 summary of knowledge points and common problems in redis class
Rhcsa Road
[cloud lesson] EI lesson 47 Mrs offline data analysis - processing OBS data through Flink
Use of OLED screen