【ZZULIOJ】几道水题

xiaoxiao2021-02-28  101

1 数独 Description

数独(すうどく,Sudoku)是一种运用纸、笔进行演算的逻辑游戏。玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行、每一列内的数字均含1-9,不重复。 小明很喜欢玩数独这个游戏,但是又觉得每次去检查数独是否合法很麻烦。所以他希望大家帮他写一个判断数独的程序。 Input

首先输入一个整数T,表示接下来有T个测试实例。 每个实例是一个9*9的数阵,在这个数阵中包含1~9这9个数字。 Output

如果数独合法,输出“Yes”,否则输出“No”。每个输出占一行。 具体输出见样例。 Sample Input

2 7 1 2 4 6 9 3 5 8 3 6 5 2 8 7 1 9 4 4 9 8 5 1 3 6 7 2 9 2 4 1 5 6 8 3 7 5 7 6 3 9 8 2 4 1 1 8 3 7 2 4 9 6 5 2 3 1 9 7 5 4 8 6 6 4 7 8 3 2 5 1 9 8 5 9 6 4 1 7 2 3

7 1 2 4 6 9 3 5 8 3 6 5 2 8 7 1 9 4 4 9 8 5 1 3 6 7 2 9 2 4 1 5 6 8 3 7 5 7 6 3 9 8 2 4 1 1 8 3 7 2 4 9 6 5 2 3 1 9 7 5 4 8 6 6 4 7 8 3 2 5 1 9 9 9 9 9 9 9 9 9 9 Sample Output

Yes No HINT

代码

#include<bits/stdc++.h> #define LL long long using namespace std; const int MAXN =100; const int MAXM = 200000; int mp[MAXN][MAXN]; set<int>S; int main(){ int t;cin>>t; while(t--){ int n; n=9; int cnt=0; S.clear(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d",&mp[i][j]); S.insert(mp[i][j]); } if(S.size()==9) cnt++; S.clear(); } S.clear();int ans=0; for(int j=1;j<=n;j++){ for(int i=1;i<=n;i++){ S.insert(mp[i][j]) ; } if(S.size()==9) ans++; S.clear(); } if(ans==cnt&&cnt==9) puts("Yes"); else puts("No"); } return 0; }

2 Happy Thanksgiving Day - A + B Problem Description

感恩节到了,yjj就想出个简单的题目让大家都能做出来。众所周知,在yjj的世界里有很多很神奇的事情,比如如果有两个整数A和B,把它们相加得到C,这个C会具有神奇的魔力:它会自动调整它各个位上的数字使得自己变得最大。那么现在yjj就想考考大家,给大家A和B,问在yjj的世界里答案是多少?

Input

输入包含多组测试样例,直到文件结束。 每组样例包含两个整数A和B用一个空格隔开。(0<=A,B<=999,100<=(A+B)<=999)

Output

对于每组样例,输出一个整数代表yjj世界里的答案。

Sample Input

100 2 Sample Output

210 HINT

Source 代码

#include<bits/stdc++.h> #define LL long long using namespace std; const int MAXN =100; const int MAXM = 200000; int main(){ int a,b; while(~scanf("%d%d",&a,&b)){ int c=a+b; string s=""; while(c){ s+=c%10+'0'; c/=10; } sort(s.begin(),s.end()); reverse(s.begin(),s.end()); cout<<s<<endl; }

括号匹配 Description

给你一个字符串,里面只有两种字符”(“和”)”。问是否所有”(“都有一个”)”与之匹配。

Input

第一行一个数字T (0

#include<bits/stdc++.h> #define LL long long using namespace std; const int MAXN = 10000+10; const int MAXM = 1e5; char str[MAXN]; int main(){ int t;cin>>t; while(t--){ stack<char>S; int flag=1; scanf("%s",str); for(int i=0;str[i];i++){ if(str[i]=='(') S.push(str[i]); else { if(S.empty()) { flag=0;break; }else if(S.top()=='(') S.pop(); } } if(!S.empty()) flag=0; if(flag) puts("yes"); else puts("no"); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-61342.html

最新回复(0)