A - chukodai
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points100100
Problem Statement
You are given a string consisting of lowercase English letters.SS
Swap the -th and -th characters from the beginning of and print the resulting string.aabbSS
Constraints
- SS is a string consisting of lowercase English letters.
- The length of , , satisfies .SS|S|∣S∣2 \leq |S| \leq 102≤∣S∣≤10
- 1 \leq a < b \leq |S|1≤a<b≤∣S∣
- aa and are integers.bb
Input
Input is given from Standard Input in the following format:
SS
aa bb
Output
Print the answer.
Sample Input 1
chokudai
3 5
Sample Output 1
chukodai
After swapping the -rd character and -th character of , we have .33o
55u
chokudai
chukodai
Sample Input 2
aa
1 2
Sample Output 2
aa
In this sample, after swapping the -st and -nd characters of , we have the same string as .1122SSSS
Sample Input 3
aaaabbbb
1 8
Sample Output 3
baaabbba
思路:直接来,数组元素交换
#include<stdio.h>
int main(){
char a[100];
scanf("%s",a);
int n,m;
scanf("%d%d",&n,&m);
n--;
m--;
char temp=a[n];
a[n]=a[m];
a[m]=temp;
printf("%s",a);
}
可以用c++里的sawp,某大佬的源码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define pb push_back
#define fir first
#define sec second
#define SZ(x) ((int)x.size())
#define pii pair<int,int>
template<class T1,class T2>void ckmin(T1&x,T2 y){if(x>y)x=y;}
template<class T1,class T2>void ckmax(T1&x,T2 y){if(x<y)x=y;}
inline int read(){
int x=0,f=0;char ch=getchar();
while(!isdigit(ch))f|=ch=='-',ch=getchar();
while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
return f?-x:x;
}
template<class T>void print(T x){
if(x<0)putchar('-'),x=-x;
if(x>=10)print(x/10);
putchar(x%10+'0');
}
template<class T>void print(T x,char let){print(x),putchar(let);}
string s;int a,b;
int main(){
cin>>s>>a>>b;
a--,b--,swap(s[a],s[b]);
cout<<s;
}
B - Who is missing?
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points200200
Problem Statement
We have cards with an integer written on it, cards with , , cards with , for a total of cards.44114422\ldots…44NN4N4N
Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining cards. The -th card of the pile has an integer written on it.4N-14N−1ii(1 \leq i \leq 4N - 1)(1≤i≤4N−1)A_iAi
Find the integer written on the card removed by Takahashi.
Constraints
- 1 \leq N \leq 10^51≤N≤105
- 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)1≤Ai≤N(1≤i≤4N−1)
- For each , there are at most indices such that .k \, (1 \leq k \leq N)k(1≤k≤N)44iiA_i = kAi=k
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN
A_1A1 A_2A2 \ldots… A_{4N - 1}A4N−1
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 written on it.33
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
思路:每种数有四个,直接用一个一个的桶装起来
#include<stdio.h>
int a[100001];
int main()
{
int n;
scanf("%d",&n);
int k;
for(int i=0;i<4*n-1;i++){
scanf("%d",&k);
a[k]++;
}
for(int i=1;i<=n;i++){
if(a[i]!=4)
printf("%d",i);
}
}
c++
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int x = 0;
for (int i = 0; i < 4 * n - 1; i++) {
int y;
cin >> y;
x ^= y;
}
cout << x << '\n';
return 0;
}
使用x^=y,当y输入是两个相同的元素时,则x=0,所以可以统计出少的那个数(因为只会少一个数)
C - Route Map
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points300300
Problem Statement
There are stations on a certain line operated by AtCoder Railway. The -th station from the starting station is named .NNii(1 \leq i \leq N)(1≤i≤N)S_iSi
Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only stations, and the -th stop is the station named .
Here, it is guaranteed that and , that is, express trains stop at both starting and terminal stations.M \, (M \leq N)M(M≤N)jj(1 \leq j \leq M)(1≤j≤M)T_jTjT_1 = S_1T1=S1T_M = S_NTM=SN
For each of the stations, determine whether express trains stop at that station.NN
Constrains
- 2 \leq M \leq N \leq 10^52≤M≤N≤105
- NN and are integers.MM
- S_iSi (1 \leq i \leq N)(1≤i≤N) is a string of length between and (inclusive) consisting of lowercase English letters.111010
- S_i \neq S_j \, (i \neq j)Si=Sj(i=j)
- T_1 = S_1T1=S1 and .T_M = S_NTM=SN
- (T_1, \dots, T_M)(T1,…,TM) is obtained by removing zero or more strings from and lining up the remaining strings without changing the order.(S_1, \dots, S_N)(S1,…,SN)
Input
Input is given from Standard Input in the following format:
NN MM
S_1S1 \ldots… S_NSN
T_1T1 \ldots… T_MTM
Output
Print lines. The -th line should contain if express trains stop at the -th station from the starting station, and otherwise.NNii(1 \leq i \leq N)(1≤i≤N)Yes
iiNo
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.
(时间超限一次).......
思路:火车是一直向前的所以出现过一次就不会再出现了
#include<stdio.h>
#include<string.h>
char a[100000][10];
char b[100000][10];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",a[i]);
for(int i=0;i<m;i++)
scanf("%s",b[i]);
int i=0,j=0;
while(j<m)
{
if(strcmp(a[i],b[j])==0){
printf("Yes\n");
j++;
}
else
printf("No\n");
i++;
}
return 0;
}
c++ 打表的方法,用map将数组名命名成字符串,map<string,int>mp;
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<bool> res(n, false);
map<string, int> mp;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
mp[s] = i;
}
for (int j = 0; j < m; j++) {
string s;
cin >> s;
res[mp[s]] = true;
}
for (int i = 0; i < n; i++) {
cout << (res[i] ? "Yes" : "No") << '\n';
}
return 0;
}
向量(Vector)是一个封装了动态大小数组的顺序容器(Sequence Container)。跟任意其它类型容器一样,它能够存放各种类型的对象。可以简单的认为,向量是一个能够存放任意类型的动态数组。