赞
踩
A - chukodai
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points100100
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
chukodai
After swapping the -rd character and -th character of , we have .33o
55u
chokudai
chukodai
aa
In this sample, after swapping the -st and -nd characters of , we have the same string as .1122SSSS
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
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.
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
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
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)。跟任意其它类型容器一样,它能够存放各种类型的对象。可以简单的认为,向量是一个能够存放任意类型的动态数组。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。