2022.11.12日atcoder解题报告(A~E题)

2022.11.12日atcoder解题报告(A~E题)

A . ^{-1}

Problem Statement
You are given a sequence P that is a permutation of (1,2,…,N), and an integer X. The i-th term of P has a value of Pi . Print k such that Pk=X.
Constraints
1≤N≤100
1≤X≤N
P is a permutation of (1,2,…,N).
All values in the input are integers.
Input
The input is given from Standard Input in the following format:

N X
P1 P2… PN

Output
Print the answer.

Sample Input 1
4 3
2 3 1 4
Sample Output 1
2
We have P=(2,3,1,4), so P2=3. Thus, you should print 2.

Sample Input 2
5 2
3 5 1 4 2
Sample Output 2
5
Sample Input 3
6 6
1 2 3 4 5 6
Sample Output 3
6

我的想法

读入时直接判断是否有一个数等于X即可。

代码实现

#include <bits/stdc++.h>
using namespace std;
 
int n,k,t;
 
int main(){
   
	cin >> n >> k;
	for(int i=1;i<=n;++i){
   
	   cin >> t;
	   if(t==k){
   
	      cout << i << endl;
	      break;
	   }
    }
	return 0;
}

B - Playing Cards Validation

Problem Statement
You are given N strings, each of length 2, consisting of uppercase English letters and digits. The i-th string is Si
Determine whether the following three conditions are all satisfied.
・For every string, the first character is one of H, D, C, and S.
・For every string, the second character is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K.
・All strings are pairwise different. That is, if i=j, then Si=Sj

Constraints
1≤N≤52
Si is a string of length 2 consisting of uppercase English letters and digits.
Input
The input is given from Standard Input in the following format:

N
S1 S2……SN

Output
If the three conditions are all satisfied, print Yes; otherwise, print No.

Sample Input 1
4
H3
DA
D3
SK
Sample Output 1
Yes
One can verify that the three conditions are all satisfied.

Sample Input 2
5
H3
DA
CK
H3
S7
Sample Output 2
No
Both S1 and S4 are H3, violating the third condition.

Sample Input 3
4
3H
AD
3D
KS
Sample Output 3
No
Sample Input 4
5
00
AA
XX
YY
ZZ
Sample Output 4
No

我的想法:

每次读入字符串时按照规则判断即可,同时把字符串存入一个字符串数组,在判断一下之前是否存在相同字符串即可。

代码实现:

#include <bits/stdc++.h>
using namespace std;
 
int n;
string s;
 
bool check(string s){
   
	char a=s[0];
	if(a!='H' && a!='D' && a!='C' && a!='S')
	  return false;
	a=s[1];
	if(a=='A' || a=='T' || a=='J' || a=='Q' || a=='K')
	  return true;
	a-='0';
	if(a>=2 && a<=9)
	  return true;
	return false;
}
int main(){
   
	string st[310];
	cin >> n;
	bool f=true;
	int id=0;
	for(int i=1;i<=n;++i){
   
		cin >> s;
		if(check(s)==false){
   
            f=false;
            break;
        }
        for(int j=1;j<i;++j)
           if(st[j]==s){
   
             f=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值