UVA - 227?Puzzle

?

Puzzle

?UVA - 227?

題目傳送門

注意點:每兩個輸出點間有一個換行,但最后一個輸出無換行

惡心模擬題,很卡輸入輸出!!!

AC代碼1:(自己的代碼,提交時需要選擇C++11)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char mapp[1000][1000];
bool xian(int x,int y)
{if(x<0||y<0||x>=5||y>=5)return false;return true;
}
int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int cnt=0;while(1) {ms(mapp);gets(mapp[0]);if(mapp[0][0]=='Z')break;cnt++;if(cnt!=1) printf("\n");for(int i=1;i<5;i++)gets(mapp[i]);int sx,sy;for(int i=0;i<5;i++){for(int j=0;j<5;j++){if(mapp[i][j]==' '){sx=i;sy=j;}}}char c;bool ju=false;while((c=getchar())!='0'){if(c=='\n')continue;if(ju)continue;int dx,dy;switch(c){case 'A':{dx=sx-1;dy=sy;if(!xian(dx,dy))ju=true;else {mapp[sx][sy]=mapp[dx][dy];mapp[dx][dy]=' ';sx=dx;sy=dy;break;}}case 'B':{dx=sx+1;dy=sy;if(!xian(dx,dy))ju=true;else {mapp[sx][sy]=mapp[dx][dy];mapp[dx][dy]=' ';sx=dx;sy=dy;break;}}case 'R':{dx=sx;dy=sy+1;if(!xian(dx,dy))ju=true;else {mapp[sx][sy]=mapp[dx][dy];mapp[dx][dy]=' ';sx=dx;sy=dy;break;}}case 'L':{dx=sx;dy=sy-1;if(!xian(dx,dy))ju=true;else {mapp[sx][sy]=mapp[dx][dy];mapp[dx][dy]=' ';sx=dx;sy=dy;break;}}}}c=getchar();printf("Puzzle #%d:\n",cnt);if(ju)printf("This puzzle has no final configuration.\n");else {for(int i=0;i<5;i++){for(int j=0;j<4;j++){printf("%c ",mapp[i][j]);}printf("%c\n",mapp[i][4]);}}}return 0;
}

AC代碼2:(大佬的代碼。。。)

?
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char block[5][5];
int x,y;
int input()
{for(int i=0;i<5;i++) {for(int j=0;j<5;j++) {reput:scanf("%c",&block[i][j]);if(i==0&&j==0&&block[0][0]=='Z')return 1;if(block[i][j]==13||block[i][j]==10)goto reput;if(block[i][j]==32){x=i;y=j;}}}return 0;
}
int move()
{char ch;int flag=1;while((ch=getchar())!='0') {switch(ch) {case '\n':continue;case 'A':{if(x!=0) {block[x][y]=block[x-1][y];block[x-1][y]=' ';x--;}else {flag=0;}break;}case 'B':{if(x!=4) {block[x][y]=block[x+1][y];block[x+1][y]=' ';x++;}else {flag=0;}break;}case 'L':{if(y!=0) {block[x][y]=block[x][y-1];block[x][y-1]=' ';y--;} else {flag=0;}break;}case 'R':{if(y!=4) {block[x][y]=block[x][y+1];block[x][y+1]=' ';y++;}else {flag=0;}break;}}}return flag;
}
void output(int flag)
{static int count=0;count++;if(count!=1)printf("\n");printf("Puzzle #%d:\n",count);if(flag){for(int i=0;i<5;i++){for(int j=0;j<4;j++){printf("%c ",block[i][j]);}printf("%c\n",block[i][4]);}}elseprintf("This puzzle has no final configuration.\n");
}
int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);for(;;){int flag1=input();if(flag1)break;int flag2=move();output(flag2);}return 0;
}?

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536327.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536327.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536327.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

UVA - 232????????Crossword Answers

Crossword Answers UVA - 232 題目傳送門 直接按照要求尋找遍歷一遍即可 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <m…

UVA - 1368????????DNA Consensus String

DNA Consensus String UVA - 1368 題目傳送門 解決方法&#xff1a;尋找每列中出現最多的字母。 AC代碼 #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #inc…

UVA - 202?Repeating Decimals

Repeating Decimals UVA - 202 題目傳送門 解決方法&#xff1a;模擬一下除法&#xff0c;及時記錄余數&#xff0c;當一個余數第二次出現時證明開始循環 AC代碼 #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #…

UVA - 10340????????All in All

All in All UVA - 10340 題目傳送門 將兩個字符串對比一下即可。 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> …

UVA - 1587????????Box

Box UVA - 1587 題目傳送門 解決方法&#xff1a;按照邊在12個長寬出現的次數和出現在幾個矩形里來判定就行了 總共出現一個長度&#xff0c;滿足條件 總共出現兩個長度&#xff0c;則其中一個長度在12個數里出現4次&#xff0c;并在四個矩形中出現 總共出現三個長度&#x…

UVA - 1588????????Kickdown

Kickdown UVA - 1588 題目傳送門 解決方法&#xff1a;上板不動&#xff0c;下板向左移&#xff1b;上板不動&#xff0c;下板向右移。 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #inclu…

UVA - 1339????????Ancient Cipher

Ancient Cipher UVA - 1339 題目傳送門 解決方法&#xff1a;模擬一下轉換過程即可。 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #i…

UVA - 489????????Hangman Judge

Hangman Judge UVA - 489 題目傳送門 PS.此題Udebug有毒&#xff0c;即使100組樣例全過&#xff0c;但還是WA&#xff0c;心塞。 這是我自己的代碼&#xff0c;悲催的WA了 #include <cstdio> #include <iostream> #include <algorithm> #include <cm…

UVA - 133????????The Dole Queue

The Dole Queue UVA - 133 題目傳送門 模擬一遍過程&#xff0c;注&#xff1a;可能會選中同一個人 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <c…

UVA - 213?Message Decoding

Message Decoding UVA - 213 題目傳送門 emmmm&#xff0c;此題按照紫書上的思路來即可&#xff0c;要么太復雜 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #in…

UVA - 512????????Spreadsheet Tracking

Spreadsheet Tracking UVA - 512 題目傳送門 紫書第二個思路十分巧妙&#xff0c;能用很少的代碼解出此題。 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #inclu…

UVA - 1589????????Xiangqi

Xiangqi UVA - 1589 題目傳送門 解決方法&#xff1a;判斷黑棋是否能有可以下的地方 AC代碼&#xff1a; #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #in…

UVA - 12412????????A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) UVA - 12412 題目傳送門 emmmm&#xff0c;不想表達什么&#xff0c;udbug上的數據全過&#xff0c;可就是WA。。。。 AC了的代碼&#xff08;大佬的代碼&#xff09; #include <bits/stdc.h> using namespace…

【思維】draw!

題目&#xff1a; You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if t…

【數學】Birthday

題目&#xff1a; Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a…

【遞推】Ayoub and Lost Array

題目&#xff1a;Ayoub had an array aa of integers of size nn and this array had two interesting properties: All the integers in the array were between ll and rr (inclusive). The sum of all the elements was divisible by 33. Unfortunately, Ayoub has lost hi…

Super-palindrome【字符串+思維】

Super-palindrome 時間限制: 1 Sec 內存限制: 128 MB 提交: 595 解決: 231 [提交] [狀態] [命題人:admin] 題目描述 You are given a string that is consisted of lowercase English alphabet. You are supposed to change it into a super-palindrome string in minimum ste…

Hakase and Nano【博弈】

Hakase and Nano 時間限制: 1 Sec 內存限制: 128 MB 提交: 533 解決: 155 [提交] [狀態] [命題人:admin] 題目描述 Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebble…

【思維】過分的謎題

題目描述 2060年是云南中醫學院的百年校慶&#xff0c;于是學生會的同學們搞了一個連續猜謎活動&#xff1a;共有10個謎題&#xff0c;現在告訴所有人第一個謎題&#xff0c;每個謎題的答案就是下一個謎題的線索....成功破解最后一個謎題后&#xff0c;答案就是指向獎勵的線索…

【bfs】調酒壺里的酸奶

題目描述 最近小w學了一手調酒的技巧&#xff0c;這么帥的操作&#xff0c;說不定能靠這個俘獲女神的芳心&#xff0c;為了在女神面前露一手&#xff0c;他想在學校里建一個"pub"&#xff0c;但是顯然學校不可能讓他真的建一個"pub"&#xff0c;那么他退而…