题目
A | Love Story |
B | Blank Space |
C | Mr. Perfectly Fine |
D | Gold Rush |
E | The Lakes |
F | Forever Winter |
G | Hits Different |
H | Don't Blame Me |
A. Love Story
Timur loves codeforces. That's why he has a string 𝑠 having length 1010 made containing only lowercase Latin letters. Timur wants to know how many indices string 𝑠 differs from the string "codeforces".
For example string 𝑠= "coolforsez" differs from "codeforces" in 4 indices, shown in bold.
Help Timur by finding the number of indices where string 𝑠 differs from "codeforces".
Note that you can't reorder the characters in the string 𝑠.
Input
The first line contains a single integer 𝑡 (1≤𝑡≤1000) — the number of test cases.
Each test case is one line and contains the string 𝑠, consisting of exactly 10 lowercase Latin characters.
Output
For each test case, output a single integer — the number of indices where string 𝑠 differs.
Example
INPUT
5
coolforsez
cadafurcie
codeforces
paiuforces
forcescode
OUTPUT
4 5 0 4 9
#include <bits/stdc++.h>
using namespace std;
void MainSolve() {
string s = "codeforces";
int ans = 0;
for(int i = 0;i<10;++i) {
char c;
cin >> c;
ans += (s[i] != c); //此处ans所加的数是一个布尔值,如果s[i]没有对应上c,返回1,ans加一
}
cout << ans << endl;
}
int main() {
int T;
cin>>T; //input test cases
while(T--){
MainSolve();
}
return 0;
}
B. Blank Space
You are given a binary array 𝑎 of 𝑛 elements, a binary array is an array consisting only of 0s and 1s.
A blank space is a segment of consecutive elements consisting of only 0s.
Your task is to find the length of the longest blank space.
Input
The first line contains a single integer 𝑡 (1≤𝑡≤1000) — the number of test cases.
The first line of each test case contains a single integer 𝑛 (1≤𝑛≤100) — the length of the array.
The second line of each test case contains 𝑛 space-separated integers 𝑎𝑖 (0≤𝑎𝑖≤1) — the elements of the array.
Output
For each test case, output a single integer — the length of the longest blank space.
Example
input
Copy
5
5
1 0 0 1 0
4
0 1 1 1
1
0
3
1 1 1
9
1 0 0 0 1 0 0 0 1
output
Copy
2 1 1 0 3
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
while(N--) {
int n,fi=0,la=0;
cin >> n;
int a[n];
for(int i=0; i<n; i++) cin >> a[i];
for(int i=0; i<n; i++) {
if(a[i] == 0) la++;
else {
if(la > fi) fi = la;
la = 0;
}
}
if(la > fi) fi = la;
cout << fi << endl;
}
}
C. Mr. Perfectly Fine
Victor wants to become "Mr. Perfectly Fine". For that, he needs to acquire a certain set of skills. More precisely, he has 2 skills he needs to acquire.
Victor has 𝑛 books. Reading book 𝑖 takes him 𝑚𝑖 minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length 2.
What is the minimum amount of time required so that Victor acquires all of the two skills?
Input
The input consists of multiple test cases. The first line contains an integer 𝑡 (1≤𝑡≤1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer 𝑛 (1≤𝑛≤2⋅105) — the number of books available.
Then 𝑛 lines follow. Line 𝑖 contains a positive integer 𝑚𝑖 (1≤𝑚𝑖≤2⋅105) and a binary string of length 2, where 𝑠𝑖1=1 if reading book 𝑖 acquires Victor skill 1, and 𝑠𝑖1=0 otherwise, and 𝑠𝑖2=1 if reading book 𝑖 acquires Victor skill 2, and 𝑠𝑖2=0 otherwise.
It is guaranteed that the sum of 𝑛 over all test cases doesn't exceed 2⋅1052⋅105.
Output
For each test case, output a single integer denoting the minimum amount of minutes required for Victor to obtain both needed skills and −1 in case it's impossible to obtain the two skills after reading any amount of books.
Example
input
6
4
2 00
3 10
4 01
4 00
5
3 01
3 01
5 01
2 10
9 10
1
5 11
3
9 11
8 01
7 10
6
4 01
6 01
7 01
8 00
9 01
1 00
4
8 00
9 10
9 11
8 11
output
Copy
7 5 5 9 -1 8
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
int ans = INF;
int x0 = INF;
int x1 = INF;
for (int i = 0; i < n; i++) {
int k;
string s;
cin >> k >> s;
if (s == "11") ans = min(ans, k);
if (s[0] == '1') x0 = min(x0, k);
if (s[1] == '1') x1 = min(x1, k);
}
ans = min(ans, x0+x1);
if (ans == INF) ans = -1;
cout << ans << '\n';
}
}