A - chukodai
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points100100
Problem StatementYou 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
ConstraintsSS is a string consisting of lowercase English letters.The length of , , satisfies .SS|S|∣S∣2 leq |S| leq 102≤∣S∣≤101 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 bbOutput
Print the answer.
Sample Input 1
chokudai 3 5Sample Output 1
chukodai
After swapping the -rd character and -th character of , we have .33o55uchokudaichukodai
Sample Input 2
aa 1 2Sample 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 8Sample Output 3
baaabbba
#includeint 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,某大佬的源码
#includeusing 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 template void ckmin(T1&x,T2 y){if(x>y)x=y;} template void ckmax(T1&x,T2 y){if(x void print(T x){ if(x<0)putchar('-'),x=-x; if(x>=10)print(x/10); putchar(x%10+'0'); } template 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< B - Who is missing?
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points200200
Problem StatementWe have cards with an integer written on it, cards with , , cards with , for a total of cards.44114422ldots…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.
Constraints1 leq N leq 10^51≤N≤1051 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=kAll values in input are integers.
InputInput is given from Standard Input in the following format:
NN A_1A1 A_2A2 ldots… A_{4N - 1}A4N−1OutputPrint the answer.
Sample Input 13 1 3 2 3 3 2 2 1 1 1 2Sample Output 13Takahashi removed a card with written on it.33
Sample Input 21 1 1 1Sample Output 21
Sample Input 34 3 2 1 1 2 4 4 4 4 3 1 3 2 1 3Sample Output 32思路:每种数有四个,直接用一个一个的桶装起来
#includeint 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++
#includeusing 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 StatementThere 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=SNFor each of the stations, determine whether express trains stop at that station.NN
Constrains2 leq M leq N leq 10^52≤M≤N≤105NN and are integers.MMS_iSi (1 leq i leq N)(1≤i≤N) is a string of length between and (inclusive) consisting of lowercase English letters.111010S_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)
InputInput is given from Standard Input in the following format:
NN MM S_1S1 ldots… S_NSN T_1T1 ldots… T_MTMOutputPrint 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)YesiiNo
Sample Input 15 3 tokyo kanda akiba okachi ueno tokyo akiba uenoSample Output 1Yes No Yes No Yes
Sample Input 27 7 a t c o d e r a t c o d e rSample Output 2Yes Yes Yes Yes Yes Yes YesExpress trains may stop at all stations.
(时间超限一次).......
思路:火车是一直向前的所以出现过一次就不会再出现了
#include#include char a[100000][10]; char b[100000][10]; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i c++ 打表的方法,用map将数组名命名成字符串,map
mp; #includeusing 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 res(n, false); map 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)。跟任意其它类型容器一样,它能够存放各种类型的对象。可以简单的认为,向量是一个能够存放任意类型的动态数组。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)