目录
A. YES or YES?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There is a string ss of length 33, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable.
Input
The first line of the input contains an integer tt (1≤t≤1031≤t≤103) — the number of testcases.
The description of each test consists of one line containing one string ss consisting of three characters. Each character of ss is either an uppercase or lowercase English letter.
Output
For each test case, output "YES" (without quotes) if ss satisfies the condition, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
Example
input
10 YES yES yes Yes YeS Noo orZ yEz Yas XES
output
YES YES YES YES YES NO NO NO NO NO
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int tmp1=0,tmp2=0,tmp3=0;
for(int i=0;i<s.size();i++)
{
if(s[0]=='Y'||s[0]=='y') tmp1++;
if(s[1]=='E'||s[1]=='e') tmp2++;
if(s[2]=='S'||s[2]=='s') tmp3++;
}
if(tmp1!=0&&tmp2!=0&&tmp3!=0)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
B. ICPC Balloons
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
In an ICPC contest, balloons are distributed as follows:
- Whenever a team solves a problem, that team gets a balloon.
- The first team to solve a problem gets an additional balloon.
A contest has 26 problems, labelled AA, BB, CC, ..., ZZ. You are given the order of solved problems in the contest, denoted as a string ss, where the ii-th character indicates that the problem sisi has been solved by some team. No team will solve the same problem twice.
Determine the total number of balloons that the teams recieved. Note that some problems may be solved by none of the teams.
Input
The first line of the input contains an integer tt (1≤t≤1001≤t≤100) — the number of testcases.
The first line of each test case contains an integer nn (1≤n≤501≤n≤50) — the length of the string.
The second line of each test case contains a string ss of length nn consisting of uppercase English letters, denoting the order of solved problems.
Output
For each test case, output a single integer — the total number of balloons that the teams received.
Example
input
6 3 ABA 1 A 3 ORZ 5 BAAAA 4 BKPT 10 CODEFORCES
output
5 2 6 7 8 17
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string s;
cin>>s;
set<char> st;
for(int i=0;i<s.size();i++)
{
st.insert(s[i]);
}
int tmp=st.size();
cout<<tmp*2+n-st.size()<<endl;
}
return 0;
}
C. Cypher
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Luca has a cypher made up of a sequence of nn wheels, each with a digit aiai written on it. On the ii-th wheel, he made bibi moves. Each move is one of two types:
- up move (denoted by UU): it increases the ii-th digit by 11. After applying the up move on 99, it becomes 00.
- down move (denoted by DD): it decreases the ii-th digit by 11. After applying the down move on 00, it becomes 99.
Example for n=4n=4. The current sequence is 0 0 0 0.
Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
Input
The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the number of wheels.
The second line contains nn integers aiai (0≤ai≤90≤ai≤9) — the digit shown on the ii-th wheel after all moves have been performed.
Then nn lines follow, the ii-th of which contains the integer bibi (1≤bi≤101≤bi≤10) and bibi characters that are either UU or DD — the number of moves performed on the ii-th wheel, and the moves performed. UU and DD represent an up move and a down move respectively.
Output
For each test case, output nn space-separated digits — the initial sequence of the cypher.
Example
input
3 3 9 3 1 3 DDD 4 UDUU 2 DU 2 0 9 9 DDDDDDDDD 9 UUUUUUUUU 5 0 5 9 8 3 10 UUUUUUUUUU 3 UUD 8 UUDUUDDD 10 UUDUUDUDDU 4 UUUU
output
2 1 1 9 0 0 4 9 6 9
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int j=0;
while(n--)
{
int b;
string s;
cin>>b>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='D')
{
if(a[j]==9) a[j]=0;
else a[j]+=1;;
}
if(s[i]=='U')
{
if(a[j]==0) a[j]=9;
else a[j]-=1;
}
}
cout<<a[j]<<' ';
j++;
}
cout<<endl;
}
return 0;
}
D. Double Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given nn strings s1,s2,…,sns1,s2,…,sn of length at most 88.
For each string sisi, determine if there exist two strings sjsj and sksk such that si=sj+sksi=sj+sk. That is, sisi is the concatenation of sjsj and sksk. Note that jj can be equal to kk.
Recall that the concatenation of strings ss and tt is s+t=s1s2…spt1t2…tqs+t=s1s2…spt1t2…tq, where pp and qq are the lengths of strings ss and tt respectively. For example, concatenation of "code" and "forces" is "codeforces".
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the number of strings.
Then nn lines follow, the ii-th of which contains non-empty string sisi of length at most 88, consisting of lowercase English letters. Among the given nn strings, there may be equal (duplicates).
The sum of nn over all test cases doesn't exceed 105105.
Output
For each test case, output a binary string of length nn. The ii-th bit should be 11 if there exist two strings sjsj and sksk where si=sj+sksi=sj+sk, and 00 otherwise. Note that jj can be equal to kk.
Example
input
3 5 abab ab abc abacb c 3 x xx xxx 8 codeforc es codes cod forc forces e code
output
10100 011 10100101
思路:拆分字符串,判断拆分的字符串在不在已输入的字符里。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string ans=""; //保存二进制结果
vector<string> a(n); //字符串数组
map<string,int> mp; // map标记
for(int i=0;i<n;i++)
{
cin>>a[i];
mp[a[i]]=1;
}
for(int i=0;i<n;i++) //遍历字符串
{
string s="";
int ok=0;
for(int j=0;j<a[i].size();j++) //拆分字符串
{
s+=a[i][j];
string c="";
for(int k=j+1;k<a[i].size();k++)
{
c+=a[i][k];
}
if(mp.count(s)==1 && mp.count(c)==1) //判断在不在已标记的mp里面
{
ok=1;
}
}
if(ok==1) ans+='1';
else ans+='0';
}
cout<<ans<<endl;
}
return 0;
}