寒假养成计划——Day5

A题

题目链接

Problem Statement

You are given a string S consisting of lowercase English letters.

Swap the a-th and b-th characters from the beginning of S and print the resulting string.

Constraints

  • S is a string consisting of lowercase English letters.
  • The length of S, ∣S∣, satisfies 2≤∣S∣≤10.
  • 1≤a<b≤∣S∣
  • a and b are integers.

Input

Input is given from Standard Input in the following format:

S
a b

Output

Print the answer.


Sample Input 1

chokudai
3 5

Sample Output 1

chukodai

After swapping the 3-rd character o and 5-th character u of chokudai, we have chukodai.


Sample Input 2

aa
1 2

Sample Output 2

aa

In this sample, after swapping the 1-st and 2-nd characters of S, we have the same string as S.


Sample Input 3

aaaabbbb
1 8

Sample Output 3

baaabbba

题解:

        额……这道题过于简单,就不写题解了……

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
	string s;
	int a,b;
	cin>>s;
	cin>>a>>b;
	char t=s[a-1];
	s[a-1]=s[b-1];
	s[b-1]=t;
	cout<<s<<endl;
	return 0;
}

B题

题目链接

Problem Statement

We have 4 cards with an integer 1 written on it, 4 cards with 2, …, 4 cards with N, for a total of 4N cards.

Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining 4N-1 cards. The i-th card (1≤i≤4N−1) of the pile has an integer Ai​ written on it.

Find the integer written on the card removed by Takahashi.

Constraints

  • 1≤N≤10^{5}
  • 1≤Ai​≤N(1≤i≤4N−1)
  • For each k(1≤k≤N), there are at most 4 indices i such that Ai​=k.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
  …… 

Output

Print the answer.


Sample Input 1

3
1 3 2 3 3 2 2 1 1 1 2

Sample Output 1

3

Takahashi removed a card with 33 written on it.


Sample Input 2

1
1 1 1

Sample Output 2

1

Sample Input 3

4
3 2 1 1 2 4 4 4 4 3 1 3 2 1 3

Sample Output 3

2

题解:

        额……这道题过于简单,就不写题解了……

AC代码:

#include <bits/stdc++.h>
using namespace std;

const int N=1e5+5;
int a[N];

int main()
{
	int n;
	scanf("%d",&n);
	memset(a,0,sizeof(a));
	for (int i=0;i<4*n-1;i++)
	{
		int z;
		scanf("%d",&z);
		a[z]++;
	}
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]<4)
		{
			ans=i;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

C题

题目链接

Problem Statement

There are N stations on a certain line operated by AtCoder Railway. The i-th station (1≤i≤N) from the starting station is named Si​.

Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only M(M≤N) stations, and the j-th stop (1≤j≤M) is the station named Tj​.
Here, it is guaranteed that T1​=S1​ and TM​=SN​, that is, express trains stop at both starting and terminal stations.

For each of the N stations, determine whether express trains stop at that station.

Constrains

  • 2≤M≤N≤10^{5}
  • N and M are integers.
  • Si​ (1≤i≤N) is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • Si​\neqSj​(i\neqj)
  • T1​=S1​ and TM​=SN​.
  • ((T1​,…,TM​) is obtained by removing zero or more strings from (S1​,…,SN​) and lining up the remaining strings without changing the order.

Input

Input is given from Standard Input in the following format:

N M
S1​ … SN​
T1​ … TM​

Output

Print N lines. The i-th line (1≤i≤N) should contain Yes if express trains stop at the i-th station from the starting station, and No otherwise.


Sample Input 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

Sample Output 1

Yes
No
Yes
No
Yes

Sample Input 2

7 7
a t c o d e r
a t c o d e r

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

Express trains may stop at all stations.


题解:

        这道题只需要利用好vector容器即可,注意输出的格式要求。

AC代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<string> s,t;
	for (int i=0;i<n;i++)
	{
		string ss;
		cin>>ss;
		s.push_back(ss);
	}
	for (int i=0;i<m;i++)
	{
		string tt;
		cin>>tt;
		t.push_back(tt);
	}
	int cnt=0;
	for (int i=0;i<n;i++)
	{
		if (t[cnt]==s[i])
		{
			cout<<"Yes"<<endl;
			cnt++;
		}
		else
			cout<<"No"<<endl;
	}
	return 0;
}

ps:本人实力较菜,只能做出这些简单题,后面的题如果有哪位大神可以解决可以私信我,如果这里面有讲的不清楚或者有错误的,望及时指出!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值