# 100 problem in 3 weeks challenge Codeforces ## Table of content [toc] ## 1st problem :::spoiler ### [4A Watermelon](https://codeforces.com/problemset/problem/4/A) #### Explanation: ##### Có 1 quả dưa hấu với w kg. nếu w chia hết cho 2 và lớn hơn 2 thì cout YES, ngược lại thì NO #### Tag ##### `brute force` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/rJ3JjBrNle.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; unsigned long long w; int main() { cin >> w; if (w % 2 == 0 && w >= 4){cout << "YES";} else {cout << "NO";} ``` ::: --- ## 2nd problem :::spoiler ### [71A Way Too Long Words](https://codeforces.com/problemset/problem/71/A) #### Explanation: ##### Có 1 từ, nếu nó dài hơn 10 chữ cái thì cout ra chữ cái đầu tiên -> độ dài của từ trừ cho 2 -> chữ cái cuối cùng #### Tag ##### `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/H1qeZfuNgg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string c; int n; int main() { cin >> n; for (int i=1;i<=n;i++) { cin >> c; if (c.length()>10) { string first=c.substr(0,1); string last=c.substr(c.size()-1); if (i<n){cout << first<< c.length()-2 << last << endl;} else {cout << first<< c.length()-2 << last;} } else if (i < n) { cout << c << endl; } else { cout << c; } } } ``` ::: --- ## 3rd problem :::spoiler ### [231A - Team](https://codeforces.com/problemset/problem/231/A) #### Explanation: ##### Có 1 dãy số gồm 3 chữ số(tách ra bằng dấu cách), nếu trong dáy đó có hai số 1 trở lên thì tăng biến đếm, sau đó cout ra kết quả #### Tag ##### `brute force` `greedy` `*800` #### AC ![image](https://hackmd.io/_uploads/B1d8zGO4xg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n,a,b,c,d; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if (a + b + c >=2){d++;} } cout << d; } ``` ::: ## 4th problem :::spoiler ### [282A - Bit++](https://codeforces.com/problemset/problem/282/A) #### Explanation: ##### x bắt đầu = 0, nếu x++ hay ++x thì x+1, ngược lại thì x-1 #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HyRkNMu4ll.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n, out=0; string x; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x[1]=='+'){out++;} else {out--;} } cout << out; } ``` ::: --- ## 5th problem :::spoiler ### [158A - Next Round](https://codeforces.com/problemset/problem/158/A) #### Explanation: ##### Tính từ người thứ k trở lên thì họ được đi tiếp, tất nhiên là số điểm lớn hơn 0, và nhưng người có cùng số điểm với người thứ k cũng được đi tiếp #### Tag ##### `*special problem` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SJJlAMu4gl.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n, k, result; int main() { cin >> n >> k; int a[n]; for (int i = 0; i < n; i++){cin >> a[i];} for (int i = 0; i < n; i++){if (a[i]>=a[k-1] && a[i]>0){result++;}} cout << result; } ``` ::: --- ## 6th problem :::spoiler ### [50A - Domino piling](https://codeforces.com/problemset/problem/50/A) #### Explanation: ##### Cho m và n, tính số domino có thể đặt lên bàn cờ có m * n ô sao cho không cái nào lọt ra ngoài và chồng lên nhau #### Tag ##### `greedy` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/B1ecZmuNle.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int m,n,maxx; int main() { cin >> m >> n; maxx = (m*n)/2; cout << maxx; } ``` ::: --- ## 7th problem :::spoiler ### [263A - Beautiful Matrix](https://codeforces.com/problemset/problem/263/A) #### Explanation: ##### Cho một bảng 5x5, có 1 số 1 nằm bất kì trên bẳng, còn lại là 0, tính số bước cần thiết ít nhất để di chuyển số 1 về trung tâm #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SygQVSKNee.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int i, j, x; int main() { for (i=1; i<=5; i++) { for (j=1; j<=5; j++) { cin >> x; if (x==1){cout << abs(i-3) + abs(j-3); return 0;} } } } ``` ::: --- ## 8th problem :::spoiler ### [112A - Petya and Strings](https://codeforces.com/problemset/problem/112/A) #### Explanation: ##### Cho 2 dãy kí tự(a,b) có độ dài bằng nhau, đổi tất cả qua bảng mã ASCII(viết hoa hay không không quan trọng, tất nhiên là phải chyển tất cả về viết thường), nếu a<b thì cout ra -1, ngược lại thì 1, còn không thì 0 #### Tag ##### `implementation` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/B1FAdBtNgg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; transform(a.begin(), a.end(), a.begin(), ::tolower); transform(b.begin(), b.end(), b.begin(), ::tolower); for (int i=0; i<a.size(); i++) { if (a[i] < b[i]){cout << -1;return 0;} else if (a[i] > b[i]){cout << 1;return 0;} } cout << 0; return 0; } ``` ::: --- ## 9th problem :::spoiler ### [339A - Helpful Maths](https://codeforces.com/problemset/problem/339/A) #### Explanation: ##### Cho một phép toán cộng gồm 1, 2, 3, sắp xếp thứ tự từ 1 -> 3 #### Tag ##### `greedy` `implementation` `sortings` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/H1OBaFFVgl.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; int b[(a.size()/2)+1]; for (int i = 0; i < a.size(); i += 2){b[i / 2] = a[i] - '0';} sort(b, b + (a.size()/2)+1); for (int i=0; i < (a.size()/2)+1;i++) { if (i==0){cout << b[i];} else {cout << "+" << b[i];} } return 0; } ``` ::: --- ## 10th problem :::spoiler ### [236A - Boy or Girl](https://codeforces.com/problemset/problem/236/A) #### Explanation: ##### Cho một chuỗi ký tự, nếu trong chuỗi ký tự đó có số chữ cái(chỉ tính 1 lần, ví dụ 'siss' thì là s và i) là số chẵn thì cout CHAt WITH HER!, còn không thì IGNORE HIM! #### Tag ##### `brute force` `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/SJhlQqqNlg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; set<char> name; for (int i=0; i<a.size(); i++){name.insert(a[i]);} if (name.size()%2==0){cout << "CHAT WITH HER!";} else {cout << "IGNORE HIM!";} return 0; } ``` ::: --- ## 11th problem :::spoiler ### [281A - Word Capitalization](https://codeforces.com/problemset/problem/281/A) #### Explanation: ##### Cho một một chuỗi kí tự, viết hoa hữa cái đầu tiên #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/B111Iq5Vlx.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; a[0] = toupper(a[0]); cout << a; } ``` ::: --- ## 12th problem :::spoiler ### [791A - Bear and Big Brother](https://codeforces.com/problemset/problem/791/A) #### Explanation: ##### Cho a và b, mỗi năm, a x 3 còn b x 2, hỏi khi nào thì a > b và không bằng. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HJi1K9qEgg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int a, b, c; int main() { cin >> a >> b; while(a <= b){a*=3; b*=2; c++;} cout << c; return 0; } ``` ::: --- ## 13th problem :::spoiler ### [266A - Stones on the Table](https://codeforces.com/problemset/problem/266/A) #### Explanation: ##### Cho số a và dãy kí tự b, a là độ dài của b. b gồm bất kì trong cả ba kí tự R, G, B. Nếu có hai kí tự trùng nhau thì phải bỏ 1. Tính số cần bỏ để không hai kí tự nào ở kế bên nhau và trùng nhau. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HkezTc5Vgl.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int a, c; string b; int main() { cin >> a >> b; for (int i = 1; i < a; i++){if (b[i] == b[i-1]){c++;}} cout << c; return 0; } ``` ::: --- ## 14th problem :::spoiler ### [617A - Elephant](https://codeforces.com/problemset/problem/617/A) #### Explanation: ##### Cho số a, cộng từ 0 sao cho bằng a, ta có thể cộng 1, 2, 3, 4 hoặc 5. Tính số lần cộng ít nhất để bằng a #### Tag ##### `math` `*800` #### AC ![image](https://hackmd.io/_uploads/r1PRCq5Exx.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int a; int main() { cin >> a; cout << (a+4)/5; } ``` --- ::: ## 15th problem :::spoiler ### [546A - Soldier and Bananas](https://codeforces.com/problemset/problem/546/A) #### Explanation: ##### Cho k, n, w. Tính k*((w*(w+1))/2) - n. #### Tag ##### `brute force` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/r1-sQi5Ngg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int k, n, w; int main() { cin >> k >> n >> w; int total = k*((w*(w+1))/2); cout << max(0, total - n); } ``` --- ::: ## 16th problem :::spoiler ### [59A - Word](https://codeforces.com/problemset/problem/59/A) #### Explanation: ##### Cho một dãy ký tự, đếm số chữa cái in hoa(u) và in thường(l). Nếu u > l thì in dãy ký tự được in hoa, các trường hợp còn lại in thường. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/rk2ZckhVxx.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int u, l; string a; int main() { cin >> a; for (int i=0; i < a.size(); i++) { if (isupper(a[i])){u++;} else {l++;} } if (u>l){transform(a.begin(), a.end(), a.begin(), ::toupper);} else {transform(a.begin(), a.end(), a.begin(), ::tolower);} cout << a; return 0; } ``` ::: --- ## 17th problem :::spoiler ### [977A - Wrong Subtraction](https://codeforces.com/problemset/problem/977/A) #### Explanation: ##### Cho một số a và số lần b, nếu số cuối của a là 0 thì lấy a -1, nếu khác 0 thì chia 10, lặp lại phép tính với b số lần #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/BJPz1enVee.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; for (int i = 0; i<b; i++) { if (a%10 != 0){a--;} else {a/=10;} } cout << a; } ``` ::: --- ## 18th problem :::spoiler ### [110A - Nearly Lucky Number](https://codeforces.com/problemset/problem/110/A) #### Explanation: ##### Cho một số, tính số may mắn có trong đó, nếu số lượng số may mắn là số may mắn thì cout YES, ngược lại thì NO #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SJyOgSnVel.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; bool lucky(unsigned long long b) { if (b == 0){return false;} // fix for count = 0 while (b > 0) { if (b % 10 != 7 && b % 10 != 4){return false;} b /= 10; } return true; } int main() { unsigned long long a, b = 0; cin >> a; while (a > 0) { if (a % 10 == 7 || a % 10 == 4){b++;} a /= 10; } if (lucky(b)){cout << "YES";} else {cout << "NO";} } ``` --- ::: ## 19th problem :::spoiler ### [734A - Anton and Danik](https://codeforces.com/problemset/problem/734/A) #### Explanation: ##### Cho một dãy kí tự c, tính số lần 'A' và 'D' xuất hiện, nếu 'A' > 'D', cout Anton, ngược lại thì là Danik, nếu bằng nhau thì là Friendship #### Tag ##### `string` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SJebGenEgg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n, a, d; string c; int main() { cin >> n >> c; for (int i = 0; i<n; i++) { if (c[i]=="A"){a++;} else {d++;} } if (a > d){cout << "Anton";} else if (a < d){cout << "Danik";} else {cout << "Friendship";} } ``` ::: --- ## 20th problem :::spoiler ### [41A - Translation](https://codeforces.com/problemset/problem/41/A) #### Explanation: ##### Cho a và b, đảo ngược a, nếu a giống b thì cout YES, nếu không thì NO #### Tag ##### `string` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/rkUMzShNel.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; reverse(a.begin(), a.end()); if (a == b){cout << "YES";} else {cout << "NO";} } ``` ::: --- ## 21st problem :::spoiler ### [677A - Vanya and Fence](https://codeforces.com/problemset/problem/677/A) #### Explanation: ##### Cho n và h, n là số bạn, h chiều cao hàng rào, sau đó là chiều cao của n bạn, nếu chiều cao của 1 vạn thấp hơn hoặc băng h thì chiều rộng ++, nếu cao hơn thì cộng 2, in ra kết quả là tổng chiêu rộng #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SkckI0hNxg.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n, h, total=0; int main() { cin >> n >> h; int a[n]; for (int i = 0; i<n; i++) { cin >> a[i]; if (a[i] > h){total += 2;} else {total++;} } cout << total; } ``` ::: --- ## 22nd problem :::spoiler ### [116A - Tram](https://codeforces.com/problemset/problem/116/A) #### Explanation: ##### Cho n là số trạm dừng, tính số người trên xe nhiều nhất #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SJv830hVlx.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; int n, pas=0, mini=0; int main() { cin >> n; int a[n]; int b[n]; for (int i = 0; i<n; i++) { cin >> a[i] >> b[i]; pas = pas - a[i] + b[i]; mini = max(mini, pas); } cout << mini; } ``` ::: --- ## 23rd problem :::spoiler ### [271A - Beautiful Year](https://codeforces.com/problemset/problem/271/A) #### Explanation: ##### Cho một năm, in ra năm lớn hơn năm đó và trong năm được in ra không có số nào giống nhau. Vd: 2012 -> 2013; 2013 -> 2014. Trong 2013 không có só nào giống nhau và 2014 cũng vậy #### Tag ##### `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/Bko9zkaNex.png) #### Code :::spoiler Code ```C++ #include <bits/stdc++.h> using namespace std; bool distinct(int n) { int d1 = n%10; int d2 = (n/10)%10; int d3 = (n/100)%10; int d4 = (n/1000)%10; if (d1 != d2 && d1 != d3 && d1 != d4 && d2 != d3 && d2 != d4 && d3 != d4){return true;} return false; } int n; int main() { cin >> n; n++; while (distinct(n) != true){n++;} cout << n; } ``` ::: --- ## 24th problem :::spoiler ### [1030A - In Search of an Easy Problem](https://codeforces.com/problemset/problem/1030/A) #### Explanation: ##### Cho một số n, số đó là số người đưa ra ý kiến, nếu có số 1 thì HARD, ngược lại thì EASY. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HJZbDJpVll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int a[n] for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1){cout << "HARD"; return 0;} } cout << "EASY"; return 0; } ``` ::: --- ## 25th problem :::spoiler ### [266B - Queue at the School](https://codeforces.com/problemset/problem/266/B) #### Explanation: ##### Cho n và t, n là số học sinh và t là thời gian hay số lần, sau mỗi một lần B sẽ đổi chỗ với G ở ngay dằng sau, lặp lại hành động này t lần, in ra lại chuỗi #### Tag ##### `constructive algorithms` `graph matchings` `implementation` `shortest paths` `*800` #### AC ![image](https://hackmd.io/_uploads/SyXsy-TEle.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, t; string a; int main() { cin >> n >> t >> a; for (int i=1; i <= t; i++) { for (int i = 0; i < a.size()-1; i++) { if (a[i] == 'B' && a[i + 1] == 'G'){swap(a[i], a[i + 1]);i++;} } } cout << a; } ``` ::: --- ## 26th problem :::spoiler ### [467A - George and Accommodation](https://codeforces.com/problemset/problem/467/A) #### Explanation: ##### Cho n phòng. Mỗi phòng có p người đang ở và sức chứa tối đa là q. Nếu một phòng còn ít nhất 2 chỗ trống (q - p ≥ 2), George có thể chuyển vào. Đếm số lượng phòng thỏa điều kiện đó. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/Hy6wJIAElx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, c = 0; int main() { cin >> n; int p[n], m[n]; for (int i = 0; i < n; i++) { cin >> p[i] >> m[i]; if(m[i] - p[i] >= 2){c++;} } cout << c; } ``` ::: --- ## 27th problem :::spoiler ### [344A - Magnets](https://codeforces.com/problemset/problem/344/A) #### Explanation: ##### Cho dãy n cục nam châm, mỗi cục có dạng 10 hoặc 01. Mỗi khi hai cục liên tiếp có cực khác nhau, một nhóm mới được tạo. Yêu cầu đếm tổng số nhóm cần thiết để gom các cục nam châm theo cùng cực. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SkO_M804ex.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, c = 1, s=0; int main() { cin >> n >> s; int m[n]; m[0] = s; for (int i = 1; i < n; i++) { cin >> m[i]; if(m[i] != s){c++;s = m[i];} } cout << c; } ``` ::: --- ## 28th problem :::spoiler ### [486A - Calculating Function](https://codeforces.com/problemset/problem/486/A) #### Explanation: ##### Cho số nguyên dương n. Định nghĩa hàm f(n) như sau: f(n) = -1 + 2 - 3 + 4 - 5 + ... ± n. Yêu cầu tính giá trị của f(n). #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/ByyZUIA4lx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long n, total = 0; int main() { cin >> n; long long k = n / 2; cout << k * (k + 1) - (n - k) * (n - k); } ``` ::: --- ## 29th problem :::spoiler ### [1A - Theatre Square](https://codeforces.com/problemset/problem/1/A) #### Explanation: ##### Cho một hình chữ nhật kích thước n × m. Cần lát toàn bộ bằng các viên gạch hình vuông có cạnh dài a. Không được cắt viên gạch, không được xoay, các cạnh của viên gạch phải song song với hình chữ nhật. Cho phép lát tràn ra ngoài miễn là toàn bộ hình chữ nhật được phủ kín. Yêu cầu: Tìm số lượng viên gạch tối thiểu cần dùng. #### Tag ##### `math` `*1000` #### AC ![image](https://hackmd.io/_uploads/S1-ztkkBge.png) #### Code :::spoiler Code ``` C++ #include <iostream> using namespace std; long long n, m ,a; int main() { cin >> n >> m >> a; long long f1 = (n + a - 1)/a; long long f2 = (m + a - 1)/a; cout << f1 * f2; return 0; } ``` ::: --- ## 30th problem :::spoiler ### [118A - String Task](https://codeforces.com/problemset/problem/118/A) #### Explanation: ##### Cho một chuỗi ký tự, in ra các phụ âm. #### Tag ##### `string` `brute force` `*900` #### AC ![image](https://hackmd.io/_uploads/SkzxsyJBxg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; transform(s.begin(), s.end(), s.begin(), ::tolower); for (int i = 0; i < s.size(); i++){if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y'){cout << '.' << s[i];}} return 0; } ``` ::: --- ## 31st problem :::spoiler ### [200B - Drinks](https://codeforces.com/problemset/problem/200/B) #### Explanation: ##### In ra trung bình cộng. #### Tag ##### `implementations` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/SkC0W1xBle.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; double total = 0; int main() { cin >> n; for (int i = 0; i < n; i++){cin >> x; total += x;} cout << fixed << setprecision(12) << total/n; } ``` ::: --- ## 32nd problem :::spoiler ### [228A - Is your horseshoe on the other hoof?](https://codeforces.com/problemset/problem/228/A) #### Explanation: ##### Bạn có 4 chiếc móng ngựa, mỗi cái có màu biểu diễn bởi số nguyên. Nếu có nhiều hơn một móng giống nhau, bạn phải mua thêm móng sao cho tất cả 4 cái khác màu nhau. Yêu cầu: Tính số móng cần mua thêm. #### Tag ##### `implementations` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/SJ4v4ygBll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int x; int main() { set<int> s; for (int i = 0; i < 4; i++){cin >> x; s.insert(x);} cout << 4 - s.size(); } ``` ::: --- ## 33rd problem :::spoiler ### [136A - Presents](https://codeforces.com/problemset/problem/136/A) #### Explanation: ##### Cho n bạn, bạn thứ i tặng quà cho bạn có số hiệu p_i. Nhiệm vụ là xác định với mỗi bạn j, ai là người đã tặng quà cho bạn ấy. #### Tag ##### `implementations` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/rySVAGlSgg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; vector<int> r; vector<int> o(n); for (int i = 1; i <= n; i++) { cin >> x; r.push_back(x); o[x - 1] = i; } for (int i = 0; i < n; i++) { if (i == 0){cout << o[i];} else {cout << " " << o[i];} } } ``` ::: --- ## 34th problem :::spoiler ### [61A - Ultra-Fast Mathematician](https://codeforces.com/problemset/problem/61/A) #### Explanation: ##### Cho hai dãy số, nếu a[i] == b[i] thì 0, nếu không thì 1, in cả dãy số và xét từng phần tử #### Tag ##### `implementations` `brute force` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/rklPJVlSeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; string a, b; int main() { cin >> a >> b; for (int i = 0; i< a.size(); i++) { if (a[i] == b[i]){cout << 0;} else {cout << 1;} } } ``` ::: --- ## 35th problem :::spoiler ### [705A - Hulk](https://codeforces.com/problemset/problem/705/A) #### Explanation: ##### Cho một số, in ra số n câu. Lần lượt là I hate that và I love that, câu cuối kết thúc bằng it thay cho that. #### Tag ##### `implementations` `brute force` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/rko_XEgrxl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { if (i % 2 == 0){cout << " I love ";} else {cout << " I hate ";} if (i == n) {cout << "it";} else {cout << "that";} } } ``` ::: --- ## 36th problem :::spoiler ### [1328A - Divisibility Problem](https://codeforces.com/problemset/problem/1328/A) #### Explanation: ##### Cho hai số nguyên a và b. Cần tìm số nguyên dương nhỏ nhất x sao cho a + x chia hết cho b. Nếu a đã chia hết cho b thì x = 0. Ngược lại, cần biết phải cộng thêm bao nhiêu để a trở thành bội của b. #### Tag ##### `implementations` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/Hy4BZNZBel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long n, a, b; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; if (a % b == 0){cout << 0;} else {cout << b - (a % b);} if (i < n - 1){cout << "\n";} } } ``` ::: --- ## 37th problem :::spoiler ### [520A - Pangram](https://codeforces.com/problemset/problem/520/A) #### Explanation: ##### Cho chuỗi s, nếu s có tất cả các chữ cái trong bảng chữ cái thì cout YES, nếu không thì NO. #### Tag ##### `implementations` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/HJfyHV-rlx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n >> s; transform(s.begin(), s.end(), s.begin(), ::tolower); set <char> a; for (int i = 0; i < n; i++){a.insert(s[i]);} if (a.size() == 26){cout << "YES"; return 0;} cout << "NO"; } ``` ::: --- ## 38th problem :::spoiler ### [469A - I Wanna Be the Guy](https://codeforces.com/problemset/problem/469/A) #### Explanation: ##### Cho n, p và q. n là số vong, p là số vòng của x, q là số vòng của y, nếu số vòng của cả x và y gồm các số từ 1 -> n thì cout I become the guy.; nếu không thì Oh, my keyboard! #### Tag ##### `implementations` `*800` #### AC ![image](https://hackmd.io/_uploads/BkANwV-rxl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, p, q, x; int main() { cin >> n >> p; set <int> a; for (int i = 0; i < p; i++){cin >> x; a.insert(x);} cin >> q; for (int i = 0; i < q; i++){cin >> x; a.insert(x);} if (a.size() == n){cout << "I become the guy."; return 0;} cout << "Oh, my keyboard!"; } ``` ::: --- ## 39th problem :::spoiler ### [144A - Arrival of the General](https://codeforces.com/problemset/problem/144/A) #### Explanation: ##### Cho một dãy số, tính số bước ít nhất cần thiết để số lớn nhất ở đầu và số nhỏ nhất ở sau. #### Tag ##### `implementations` `*800` #### AC ![image](https://hackmd.io/_uploads/SyArhNZSxg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; vector <int> a; for (int i = 0; i < n; i++){cin >> x; a.push_back(x);} int ma = max_element(a.begin(), a.end()) - a.begin(); int mi = min_element(a.rbegin(), a.rend()) - a.rbegin(); mi = n - 1 - mi; if (ma > mi){cout << ma + (n - 1 - mi) - 1;} else {cout << ma + (n - 1 - mi);} } ``` ::: --- ## 40th problem :::spoiler ### [996A - Hit the Lottery](https://codeforces.com/problemset/problem/996/A) #### Explanation: ##### Cho số nguyên n. Cần đổi số tiền này thành ít tờ nhất, với các mệnh giá: 100, 20, 10, 5, 1 #### Tag ##### `greedy` `*800` #### AC ![image](https://hackmd.io/_uploads/HybO7SbSel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a = 0; int main() { cin >> n; while (n != 0) { if(n / 100 > 0){a += n / 100; n -= 100*(n / 100);} else if(n / 20 > 0){a += n / 20; n -= 20*(n / 20);} else if(n / 10 > 0){a += n / 10; n -= 10*(n / 10);} else if(n / 5 > 0){a += n / 5; n -= 5*(n / 5);} else if(n / 1 > 0){a += n / 1; n -= 1*(n / 1);} } cout << a; } ``` ::: --- ## 41st problem :::spoiler ### [148A - Insomnia cure](https://codeforces.com/problemset/problem/148/A) #### Explanation: ##### Cho n, số nào chia hết cho k, l, m, n thì tính số đó tính tổng số chia hết cho k, l, m, n #### Tag ##### `implementation` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/S12ZOgfHxl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b, c, d, e; int main() { cin >> a >> b >> c >> d >> e; set <int> f; for (int i = 1; i <= e; i++){if (i % a == 0|| i % b == 0|| i % c == 0|| i % d == 0){f.insert(i);}} cout << f.size(); } ``` ::: --- ## 42nd problem :::spoiler ### [443A - Anton and Letters](https://codeforces.com/problemset/problem/443/A) #### Explanation: ##### Cho một chuỗi gồm các chữ cái, mở và đóng bằng dấu{}, các chữ cái được tách nhau bằng dấu phẩy và dấu cách. Tính số chữ cái, không tính những chữ bị trùng. #### Tag ##### `implementation` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/HyHa_lzBeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; string a; int main() { getline(cin, a); set <char> b; for (char c : a){if (isalpha(c)){b.insert(c);}} cout << b.size(); } ``` ::: --- ## 43rd problem :::spoiler ### [785A - Anton and Polyhedrons](https://codeforces.com/problemset/problem/785/A) #### Explanation: ##### Cho các hình khối, tính tổng số mặt. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/ryexsxfHel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b = 0; string x; int main() { cin >> a; while (cin >> x) { if (x == "Tetrahedron"){b += 4;} else if (x == "Cube"){b += 6;} else if (x == "Octahedron"){b += 8;} else if (x == "Dodecahedron"){b += 12;} else if (x == "Icosahedron"){b += 20;} } cout << b; } ``` ::: --- ## 44th problem :::spoiler ### [268A - Games](https://codeforces.com/problemset/problem/268/A) #### Explanation: ##### Cho n đội bóng, mỗi đội sẽ chơi một trận với tất cả các đội còn lại. Mỗi đội có một màu áo sân nhà và một màu áo sân khách. Một trận đấu được tổ chức trên sân của một đội, đội chủ nhà sẽ mặc áo sân nhà, còn đội khách phải mặc áo sân khách trừ khi áo sân nhà của chủ trùng màu với áo sân khách của khách, thì đội khách phải mặc áo sân nhà của mình để phân biệt. Yêu cầu đếm xem có bao nhiêu trận đấu mà đội khách phải mặc áo sân nhà của mình do bị trùng màu với đội chủ nhà. #### Tag ##### `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/r190rtzSlg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x, y, total = 0; int main() { cin >> n; vector <int> h; vector <int> a; for (int i = 0; i < n; i++) { cin >> x; h.push_back(x); cin >> y; a.push_back(y); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j){if (h[i] == a[j]){total++;}} } } cout << total; } ``` ::: --- ## 45th problem :::spoiler ### [1335A - Candies and Two Sisters](https://codeforces.com/problemset/problem/1335/A) #### Explanation: ##### Cho số nguyên dương n, đếm số cách phân chia n thành hai số nguyên dương a và b sao cho a+b=n và a>b. Mỗi cách phân chia được tính là một bộ số nguyên dương thỏa mãn hai điều kiện trên. #### Tag ##### `math` `*800` #### AC ![image](https://hackmd.io/_uploads/BkEPxCGrgl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long n, x; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (i == 0){cout << (x - 1) / 2;} else {cout << "\n" << (x - 1) / 2;} } } ``` ::: --- ## 46th problem :::spoiler ### [510A - Fox And Snake](https://codeforces.com/problemset/problem/510/A) #### Explanation: ##### Cho hai số nguyên dương `n` và `m`, in ra hình chữ nhật gồm n dòng và m cột với các ký tự `#` và `.` sao cho các dòng có chỉ số lẻ (dòng 1, 3, 5, ...) được in toàn bộ bằng ký tự `#`, còn các dòng có chỉ số chẵn thì nếu chỉ số dòng chia hết cho 4 thì dòng đó có ký tự `#` ở cuối và các vị trí còn lại là ký tự `.`, ngược lại dòng đó có ký tự # ở đầu và các vị trí còn lại là ký tự `.` #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/ByQ36rXSll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { if (i > 1){cout << "\n";} if (i % 2 != 0){for (int j = 0; j < m; j++){cout << "#";}} else if (i % 2 == 0 && i % 4 != 0) {for (int j = 0; j < m - 1; j++){cout << ".";} cout << "#";} else if (i % 2 == 0 && i % 4 == 0) {cout << "#"; for (int j = 0; j < m - 1; j++){cout << ".";}} } } ``` ::: --- ## 47th problem :::spoiler ### [141A - Amusing Joke](https://codeforces.com/problemset/problem/141/A) #### Explanation: ##### Cho ba xâu ký tự `a`, `b`, `c`. Kiểm tra xem nếu ghép `a` và `b` lại rồi sắp xếp lại, thì có bằng đúng `c` sau khi sắp xếp không. Nếu có, in ra `YES`, ngược lại in `NO`. #### Tag ##### `implementation` `strings` `sort` `*800` #### AC ![image](https://hackmd.io/_uploads/Hkd2-RXHeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; string x; int main() { vector <char> a; vector <char> b; for (int i = 1; i <= 3; i++) { cin >> x; if (i < 3){for (char d : x){a.push_back(d);}} else {for (char d : x){b.push_back(d);}} } sort(a.begin(), a.end()); sort(b.begin(), b.end()); if (a == b){cout << "YES"; return 0;} cout << "NO"; return 0; } ``` ::: --- ## 48th problem :::spoiler ### [1352A - Sum of Round Numbers](https://codeforces.com/problemset/problem/1352/A) #### Explanation: ##### Cho số nguyên dương `n`, tách `n` thành các số tròn (round numbers) sao cho tổng của chúng bằng `n`. Một số tròn là số chỉ có đúng một chữ số khác `0`, các chữ số còn lại đều là `0` (ví dụ: `400`, `90`, `5`). #### Tag ##### `implementation` `strings` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/SkFhT5NBgg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, b, c; string x; int main() { cin >> n; vector <long long> a; for (int i = 0; i < n; i++) { cin >> x; c = 0; b = 1; for (int j = x.size() - 1; j > -1; j--) { if (x[j] != '0'){a.push_back(stoll(x.substr(j,1))*b); c++;} b *= 10; } cout << c << "\n"; for (int k = 0; k < a.size(); k++) { if (k == 0) {cout << a[k];} else {cout << " " << a[k];} } cout << "\n"; a.clear(); } return 0; } ``` ::: --- ## 49th problem :::spoiler ### [723A - The New Year: Meeting Friends](https://codeforces.com/problemset/problem/723/A) #### Explanation: ##### Cho ba số nguyên `a`, `b`, `c` biểu diễn vị trí của ba người bạn trên trục số. Cần chọn một vị trí sao cho tổng khoảng cách ba người di chuyển đến điểm đó là nhỏ nhất. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/SJIDc7rSgl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b, c, total; int main() { cin >> a >> b >> c; cout << max({a, b, c}) - min({a, b, c}); return 0; } ``` ::: --- ## 50th problem :::spoiler ### [1742A - Sum](https://codeforces.com/problemset/problem/1742/A) #### Explanation: ##### Cho số nguyên dương `n`, sau đó là `n` bộ ba số nguyên `a`, `b`, `c`. Với mỗi bộ ba, kiểm tra xem có tồn tại hai số trong ba số sao cho tổng của chúng bằng số còn lại không. Nếu có, in ra `YES`, ngược lại in ra `NO`. #### Tag ##### `implementation` `brute force` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/ryV9aXBHgx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if (i > 0){cout << "\n";} if (a + b == c || a + c == b || c + b == a){cout << "YES";} else {cout << "NO";} } return 0; } ``` ::: --- ## 51st problem :::spoiler ### [427A - Police Recruits](https://codeforces.com/problemset/problem/427/A) #### Explanation: ##### Cho số nguyên `n` và dãy gồm `n` số nguyên. Mỗi số dương biểu thị số cảnh sát được tuyển thêm, mỗi số `-1` biểu thị một vụ án cần xử lý. Nếu còn cảnh sát, dùng một người để xử lý vụ án; nếu không, vụ án bị bỏ lỡ. Cần đếm tổng số vụ án bị bỏ lỡ. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/BkaiPDrSel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, officer, crime, untracked, x; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x > 0){officer+=x;} else if (x == -1){if (officer > 0){officer--;}else {untracked++;}} } cout << untracked; return 0; } ``` ::: --- ## 52nd problem :::spoiler ### [750A - New Year and Hurry](https://codeforces.com/problemset/problem/750/A) #### Explanation: ##### Cho hai số nguyên `n` và `k`. Tổng thời gian làm bài là 240 phút, trong đó `k` phút đã dùng. Bài thứ `i` cần `5*i` phút để giải. Tìm số lượng bài tối đa có thể làm từ bài 1 đến bài `n` sao cho tổng thời gian không vượt quá `240 - k`. #### Tag ##### `implementation` `math` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/rkrksDHSel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, k, total; int main() { cin >> n >> k; for (int i = 1; i <= n; i++){total += 5*i; if (240 - k < total){cout << i-1; return 0;}} cout << n; return 0; } ``` ::: --- ## 53rd problem :::spoiler ### [155A - I_love_\%username\%](https://codeforces.com/problemset/problem/155/A) #### Explanation: ##### Cho số nguyên `n` và dãy `n` số nguyên. Ban đầu lấy phần tử đầu tiên làm mốc. Mỗi khi gặp một số lớn hơn giá trị lớn nhất trước đó, hoặc nhỏ hơn giá trị nhỏ nhất trước đó, thì coi như một kỷ lục mới bị phá và tăng biến đếm thêm 1. In ra tổng số lần phá kỷ lục. #### Tag ##### `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/rymsJOHSeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, cb, cw, x, a; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (i > 0) { if (x > cb){a++; cb = x;} if (x < cw){a++; cw = x;} } if (i == 0){cb = x; cw = x;} } cout << a; return 0; } ``` ::: --- ## 54th problem :::spoiler ### [151A - Soft Drinking](https://codeforces.com/problemset/problem/151/A) #### Explanation: ##### Cho các số nguyên `n`, `k`, `l`, `c`, `d`, `p`, `nl`, `np`. Có `n` người cần nâng ly. Có `k` chai nước, mỗi chai chứa `l` ml; `c` quả chanh, mỗi quả cắt được `d` lát; và `p` gam muối. Mỗi người cần `nl` ml nước và `np` gam muối cho mỗi lần nâng ly, cùng với 1 lát chanh. Tính số lần nâng ly tối đa mà `n` người có thể thực hiện cùng lúc sao cho đủ tất cả nguyên liệu. #### Tag ##### `math` `*800` #### AC ![image](https://hackmd.io/_uploads/rymsJOHSeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, k, l, c, d, p, nl, np; int main() { cin >> n >> k >> l >> c >> d >> p >> nl >> np; cout << min({(k*l)/nl, c*d, p/np})/n; return 0; } ``` ::: --- ## 55th problem :::spoiler ### [1703A - YES or YES?](https://codeforces.com/problemset/problem/1703/A) #### Explanation: ##### Cho số nguyên `n` và `n` xâu ký tự. Với mỗi xâu, nếu sau khi chuyển toàn bộ ký tự thành chữ thường thì xâu đó bằng "yes" thì in ra "YES", ngược lại in ra "NO". #### Tag ##### `brute force` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/HJQJLOHrex.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s; transform(s.begin(), s.end(), s.begin(), ::tolower); if (s == "yes"){cout << "YES\n";} else {cout << "NO\n";} } return 0; } ``` ::: --- ## 56th problem :::spoiler ### [732A - Buy a Shovel](https://codeforces.com/problemset/problem/732/A) #### Explanation: ##### Cho hai số nguyên `n` và `k`. Tìm số nguyên dương nhỏ nhất `i` sao cho chữ số tận cùng của `n * i` bằng `0` hoặc bằng `k`. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SyK6wdSrel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, k, i = 1; int main() { cin >> n >> k; while (true){if ((n * i) % 10 == 0 || (n * i) % 10 == k){cout << i; break;}i++;} return 0; } ``` ::: --- ## 57th problem :::spoiler ### [630A - Again Twenty Five!](https://codeforces.com/problemset/problem/630/A) #### Explanation: ##### Cho số nguyên `n`. Tính hai chữ số tận cùng của `n^n`. #### Tag ##### `math` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/Sk4bs_Srel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long n; int main() { cin >> n; if (n < 10){cout << (long long)(pow(5, n)) % 100; return 0;} cout << 25; return 0; } ``` ::: --- ## 58th problem :::spoiler ### [1154A - Restoring Three Numbers](https://codeforces.com/problemset/problem/1154/A) #### Explanation: ##### Cho số nguyên `a + b`, `b + c`, `a + c`, `a + b + c` theo bất cứ thứ tự nào, tính `a`, `b`, `c`, `d` và in ra theo bất cứ thứ tự nào. #### Tag ##### `math` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/rJXgpb8Hee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long a; int main() { vector <long long> e; for (int i = 0; i < 4; i++){cin >> a; e.push_back(a);} sort(e.begin(), e.end()); cout << e[3] - e[2] << " " << e[3] - e[1] << " " << e[3] - e[0]; return 0; } ``` ::: --- ## 59th problem :::spoiler ### [581A - Vasya the Hipster](https://codeforces.com/problemset/problem/581/A) #### Explanation: ##### Cho hai số nguyên không âm `a` và `b`, lần lượt là số tất màu đỏ và màu xanh. Mỗi ngày có thể mang hai chiếc tất, trong đó có thể chọn một tất đỏ và một tất xanh, hoặc hai tất cùng màu. Tìm số ngày tối đa có thể mang hai tất khác màu và số ngày tối đa có thể mang hai tất cùng màu sau khi đã dùng hết khả năng mang hai tất khác màu. In ra hai số nguyên cách nhau bởi dấu cách, lần lượt là số ngày mang hai tất khác màu và số ngày mang hai tất cùng màu. #### Tag ##### `math` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HyBDkGUSlx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; cout << min(a, b) << " " << abs(a - b)/2; return 0; } ``` ::: --- ## 60th problem :::spoiler ### [381A - Sereja and Dima](https://codeforces.com/problemset/problem/381/A) #### Explanation: ##### Cho số nguyên `n` và một dãy số nguyên `a` gồm `n` phần tử. Hai người chơi lần lượt chọn một phần tử từ đầu hoặc cuối dãy, mỗi lần chọn một phần tử. Người chơi đầu tiên là Sereja, người thứ hai là Dima. Mỗi người cố gắng tối đa hoá tổng số điểm mà mình thu được từ các phần tử đã chọn. In ra hai số nguyên cách nhau bởi dấu cách, lần lượt là tổng điểm của Sereja và Dima sau khi toàn bộ dãy được chọn hết. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HyT7KfIHle.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, x; int main() { cin >> n; vector <int> e; for (int i = 0; i < n; i++){cin >> x; e.push_back(x);} for (int i = 0; e.size() > 0; i++) { if (e[0] > e.back()) { if(i % 2 == 0){a += e[0];} else {b += e[0];} e.erase(e.begin()); } else if (e[0] < e.back()) { if(i % 2 == 0){a += e.back();} else {b += e.back();} e.pop_back(); } else { if(i % 2 == 0){a += e.back();} else {b += e.back();} e.pop_back(); } } cout << a << " " << b; return 0; } ``` ::: --- ## 61st problem :::spoiler ### [1669A - Division?](https://codeforces.com/problemset/problem/1669/A) #### Explanation: ##### Cho một số nguyên `rating`. In ra tên của division mà `rating` thuộc vào như sau: nếu `rating` ≥ `1900` thì in `Division 1`, nếu `1600` ≤ `rating` ≤ `1899` thì in `Division 2`, nếu `1400` ≤ `rating` ≤ `1599` thì in `Division 3`, nếu `rating` ≤ `1399` thì in `Division 4`. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/rkJJ3zIHex.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; for (int i = 0; i < n; i++) { if(i > 0){cout << "\n";} cin >> x; if (x < 1400){cout << "Division 4";} else if (x < 1600){cout << "Division 3";} else if (x < 1900){cout << "Division 2";} else {cout << "Division 1";} } return 0; } ``` ::: --- ## 62nd problem :::spoiler ### [1692A - Marathon](https://codeforces.com/problemset/problem/1692/A) #### Explanation: ##### Cho bốn số nguyên `a`, `b`, `c`, `d` lần lượt là thời gian hoàn thành marathon của bốn người. Người đầu tiên có thời gian là `a`. In ra số lượng người trong ba người còn lại có thời gian hoàn thành ít hơn `a`. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/BJQtAGLBee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, x, t; int main() { cin >> n; for (int i = 0; i < n; i++) { a = 0; t = 0; for (int j = 0; j < 4; j++) { cin >> x; if (j == 0){a = x;} else { if (x > a){t++;} } } cout << t << "\n"; } return 0; } ``` ::: --- ## 63rd problem :::spoiler ### [1676A - Lucky?](https://codeforces.com/problemset/problem/1676/A) #### Explanation: ##### Cho số nguyên `t` là số lượng test. Mỗi test gồm một số nguyên `n` có đúng 6 chữ số. Một số được gọi là "may mắn" nếu tổng ba chữ số đầu tiên bằng tổng ba chữ số cuối cùng. Với mỗi test, in ra `YES` nếu `n` là số may mắn, ngược lại in ra `NO`. #### Tag ##### `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/ryxL778Bel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, x; int main() { cin >> x; for (int i = 0; i < x; i++) { cin >> n; a = 0; b = 0; for (int i = 0; i < 6; i++) { if (i < 3){a += n % 10;} else {b += n % 10;} n /= 10; } if (a == b){cout << "YES\n";} else {cout << "NO\n";} } return 0; } ``` ::: --- ## 64th problem :::spoiler ### [1807A - Plus or Minus](https://codeforces.com/problemset/problem/1676/A) #### Explanation: ##### Cho số nguyên `t` là số lượng test. Mỗi test gồm ba số nguyên `a`, `b`, `c`. Với mỗi test, nếu `a + b = c` thì in ra `+`, ngược lại in ra `-`. #### Tag ##### `math` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/r1YVEXUrll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if (a + b == c){cout << "+\n";} else {cout << "-\n";} } return 0; } ``` ::: --- ## 65th problem :::spoiler ### [1409A - Yet Another Two Integers Problem](https://codeforces.com/problemset/problem/1409/A) #### Explanation: ##### Cho số nguyên `t` là số lượng test. Mỗi test gồm hai số nguyên `a` và `b`. Trong mỗi bước, có thể cộng hoặc trừ `10` vào `a`. Tính số bước tối thiểu để biến `a` thành `b`. In ra kết quả với mỗi test trên một dòng. #### Tag ##### `math` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/H1etm8XUree.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; c = abs(b - a); if (c == 0){cout << 0 << "\n";} else { if (c % 10 != 0){cout << c / 10 + 1 << "\n";} else {cout << c / 10 << "\n";} } } return 0; } ``` ::: --- ## 66th problem :::spoiler ### [1399A - Remove Smallest](https://codeforces.com/problemset/problem/1399/A) #### Explanation: ##### Cho số nguyên `t` là số lượng test. Mỗi test gồm số nguyên `n` và một dãy `a` gồm `n` số nguyên. Có thể thực hiện thao tác bất kỳ số lần: chọn hai phần tử bất kỳ có hiệu tuyệt đối không quá `1`, rồi xoá phần tử lớn hơn. Kiểm tra xem có thể thực hiện các thao tác sao cho dãy còn lại là không giảm. In ra `YES` nếu có thể, ngược lại in ra `NO`. #### Tag ##### `sorting` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/B1AvjQLHxx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, x; int main() { cin >> n; vector <int> b; for (int i = 0; i < n; i++) { cin >> a; b.clear(); for (int j = 0; j < a; j++){cin >> x; b.push_back(x);} sort(b.begin(), b.end()); bool ok = true; if (a == 1){cout << "YES\n";continue;} for (int j = 0; j < a-1; j++){if (abs(b[j]-b[j+1]) > 1){cout << "NO\n"; ok = false; break;}} if (ok){cout << "YES\n";} } return 0; } ``` ::: --- ## 67th problem :::spoiler ### [32B - Borze](https://codeforces.com/problemset/problem/32/B) #### Explanation: ##### Cho xâu ký tự chỉ gồm `.` và `-`. Mỗi ký hiệu hoặc cặp ký hiệu tương ứng với một chữ số như sau: - `.` → `0` - `-.` → `1` - `--` → `2` ##### Hãy chuyển đổi xâu đầu vào thành dãy số nguyên tương ứng. In ra kết quả liền nhau trên một dòng. #### Tag ##### `string` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HkexRm8rgx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] == '.'){cout << "0";} if (a[i] == '-'){if (a[i+1] == '.'){cout << "1"; i++;}else {cout << "2"; i++;}} } return 0; } ``` ::: --- ## 68th problem :::spoiler ### [1512A - Spy Detected!](https://codeforces.com/problemset/problem/1512/A) #### Explanation: ##### Cho mảng gồm `n` số nguyên, trong đó có đúng một phần tử khác với các phần tử còn lại. Tìm vị tí của phần tử khác biệt đó. #### Tag ##### `algorithm` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/ryvmu4Urll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, b, x, r; int main() { cin >> n; vector <int> a, c; for (int i = 0; i < n; i++) { cin >> b; a.clear(); c.clear(); for (int j = 0; j < b; j++){cin >> x; a.push_back(x); c.push_back(x);} sort(c.begin(), c.end()); int u; if (c[0] != c[1] && c[1] == c[2]){u = c[0];} else if (c[c.size()-1] != c[c.size()-2] && c[c.size()-2] == c[c.size()-3]){u = c[c.size()-1];} cout << find(a.begin(), a.end(), u) - a.begin() + 1 << "\n"; } return 0; } ``` ::: --- ## 69th problem :::spoiler ### [1791A - Codeforces Checking](https://codeforces.com/problemset/problem/1791/A) #### Explanation: ##### Cho số nguyên dương `n` và `n` ký tự `x`. Với mỗi ký tự, kiểm tra xem ký tự đó có xuất hiện trong chuỗi `"codeforces"` hay không. Nếu có thì in ra `YES`, ngược lại in ra `NO`. #### Tag ##### `string` `brute force` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/B17ZrDIHgg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; char x; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 'c' || x == 'o' || x == 'd' || x == 'e' || x == 'f' || x == 'r' || x == 's'){cout << "YES\n";} else{cout << "NO\n";} } return 0; } ``` ::: --- ## 70th problem :::spoiler ### [1999A - A+B Again?](https://codeforces.com/problemset/problem/1999/A) #### Explanation: ##### Cho số `a` các số `b`. Với mỗi số `b`, in ra tổng của hai chữ số trong `b`. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/HyxtFpLHlx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> b; for (int i = 0; i < b; i++) { cin >> a; cout << (a % 10) + (a / 10) << "\n"; } } ``` ::: --- ## 71st problem :::spoiler ### [1760A - Medium Number](https://codeforces.com/problemset/problem/1760/A) #### Explanation: ##### Cho `n` các số `a`, `b`, `c`. Tìm số không lớn nhất và nhỏ nhất - số ở giữa. #### Tag ##### `sorting` `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/H1H4a68Slg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; vector <int> a; for (int i = 0; i < n; i++) { a.clear(); for (int j = 0; j < 3; j++){cin >> x; a.push_back(x);} sort(a.begin(), a.end()); cout << a[1] << "\n"; } } ``` ::: --- ## 72nd problem :::spoiler ### [1915A - Odd One Out](https://codeforces.com/problemset/problem/1915/A) #### Explanation: ##### Cho các số `a`, `b`, `c`. Tìm số khác biệt. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/S15CCTISee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if (a == b){cout << c << "\n";} else if (a == c){cout << b << "\n";} else if (c == b){cout << a << "\n";} } } ``` ::: --- ## 73rd problem :::spoiler ### [758A - Holiday Of Equality](https://codeforces.com/problemset/problem/758/A) #### Explanation: ##### Cho `n` số nguyên biểu diễn mức lương của `n` người. Mỗi ngày, có thể tăng lương của một người bất kỳ thêm `1`. Hỏi cần thực hiện ít nhất bao nhiêu lần tăng để mọi người có cùng mức lương. #### Tag ##### `implementation` `sorting` `*800` #### AC ![image](https://hackmd.io/_uploads/rJB5MiPrex.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x, total; int main() { cin >> n; vector <int> a; for (int i = 0; i < n; i++){cin >> x; a.push_back(x);} sort(a.begin(), a.end()); int m = a[n - 1]; for (int i = 0; i < n; i++){if(a[i] < m){total += m - a[i];}else{break;}} cout << total; } ``` ::: --- ## 74th problem :::spoiler ### [1560A - Dislike of Threes](https://codeforces.com/problemset/problem/1560/A) #### Explanation: ##### Cho `k`, yêu cầu tìm số nguyên dương thứ `k` thỏa mãn cả hai điều kiện sau: - Không chia hết cho `3` - Không có chữ số tận cùng là `3` #### Tag ##### `implementation` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/SkydriwHee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x; int count = 0; for (int j = 1;; j++) { if (j % 3 != 0 && j % 10 != 3) { count++; if (count == x){cout << j << "\n"; break;} } } } } ``` ::: --- ## 75th problem :::spoiler ### [472A - Design Tutorial: Learn from Math](https://codeforces.com/problemset/problem/472/A) #### Explanation: ##### Cho số nguyên `n ≥ 12`, yêu cầu tìm hai số nguyên dương khác 1 sao cho: - Tổng của chúng bằng `n` - Cả hai số đều là hợp số (không phải số nguyên tố) #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/SyYZDsDHgg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 2 == 0){cout << 4 << " " << n - 4;} else{cout << 9 << " " << n - 9;} } ``` ::: --- ## 76th problem :::spoiler ### [1850A - To My Critics](https://codeforces.com/problemset/problem/1850/A) #### Explanation: ##### Cho số nguyên `n` tests gồm `a`, `b`, `c`. Nếu hai số nào đó trong `a`, `b`, `c` cộng lại băng `10` thì in ra `YES` hoặc `NO` nếu không. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/S1wrTsPreg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, a, b, c; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if(a+b>=10||a+c>=10||b+c>=10){cout << "YES\n";} else {cout << "NO\n";} } } ``` ::: --- ## 77th problem :::spoiler ### [432A - Choosing Teams](https://codeforces.com/problemset/problem/432/A) #### Explanation: ##### Cho `n` sinh viên, mỗi người đã tham gia một số cuộc thi nhất định, trong khi tổng số cuộc thi mà một người được phép tham gia là 5. Mỗi đội gồm đúng 3 sinh viên, và để lập một đội, cả ba thành viên phải còn đủ điều kiện tham gia ít nhất `k` cuộc thi nữa. Nhiệm vụ là xác định số lượng đội tối đa có thể lập được theo yêu cầu này. #### Tag ##### `implementation` `brute force` `*800` #### AC ![image](https://hackmd.io/_uploads/SyW7ffOrlg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, k, x, c; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; if (5 - x >= k){c++;} } cout << c/3; } ``` ::: --- ## 78th problem :::spoiler ### [490A - Team Olympiad](https://codeforces.com/problemset/problem/490/A) #### Explanation: ##### Cho số nguyên dương `n`, cùng dãy gồm `n` số nguyên, mỗi số là `1`, `2` hoặc `3`, biểu diễn kỹ năng của từng học sinh: lập trình (`1`), toán học (`2`), hoặc thể thao (`3`). Mỗi học sinh chỉ có đúng một kỹ năng. Mỗi đội gồm đúng ba học sinh, mỗi người giỏi một kỹ năng khác nhau. Yêu cầu: tính số đội tối đa có thể lập được thoả mãn điều kiện trên. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/BJurvzOBle.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, x; int main() { cin >> n; vector <int> a; vector <int> b; vector <int> c; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1){a.push_back(i);} else if (x == 2){b.push_back(i);} else if (x == 3){c.push_back(i);} } int d = min({a.size(), b.size(), c.size()}); cout << d << "\n"; for (int i = 0; i < d; i++){cout << a[i] << " " << b[i] << " " << c[i] << "\n";} } ``` ::: --- ## 79th problem :::spoiler ### [1899A - Game with Integers](https://codeforces.com/problemset/problem/1899/A) #### Explanation: ##### Cho số nguyên dương `n`. Hai người chơi lần lượt thực hiện thao tác: trong một lượt, họ có thể tăng hoặc giảm `n` đi 1. Vanya đi trước. Nếu sau lượt đi của Vanya, giá trị của `n` chia hết cho 3 thì Vanya thắng ngay lập tức. Nếu sau 10 lượt đi (tức mỗi người chơi 5 lần) mà Vanya không thắng, thì Vova thắng. Yêu cầu: Với mỗi giá trị `n` cho trước, xác định người thắng nếu cả hai chơi tối ưu. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/BJurvzOBle.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n; int main() { cin >> t; while (t--) { cin >> n; if (n % 3 == 0){cout << "Second\n";} else {cout << "First\n";} } } ``` ::: --- ## 80th problem :::spoiler ### [1985A - Creating Words](https://codeforces.com/problemset/problem/1985/A) #### Explanation: ##### Cho số nguyên `n`, sau đó là `n` test case. Mỗi test case gồm hai chuỗi `a` và `b`, đều có độ dài đúng 2 và chỉ gồm chữ cái in thường. Yêu cầu: Với mỗi test case, hoán đổi ký tự đầu tiên của hai chuỗi `a` và `b`, sau đó in ra chuỗi `a` mới và chuỗi `b` mới sau khi hoán đổi. #### Tag ##### `implementation` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/BkLPyqOBlx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n; string a, b; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; string c = a, d = b; c[0] = b[0]; d[0] = a[0]; cout << c << " " << d << "\n"; } } ``` ::: --- ## 81st problem :::spoiler ### [9A - Die Roll](https://codeforces.com/problemset/problem/9/A) #### Explanation: ##### Cho hai số nguyên `a` và `b` (1 ≤ a, b ≤ 6). In ra phân số tối giản biểu diễn xác suất gieo một số không nhỏ hơn `max(a, b)` trên một viên xúc xắc sáu mặt. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/HJvKGcOBlg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; int chance = max(a,b); if (chance == 1){cout << "1/1";} else if (chance == 2){cout << "5/6";} else if (chance == 3){cout << "2/3";} else if (chance == 4){cout << "1/2";} else if (chance == 5){cout << "1/3";} else if (chance == 6){cout << "1/6";} } ``` ::: --- ## 82nd problem :::spoiler ### [2009A - Minimize!](https://codeforces.com/problemset/problem/2009/A) #### Explanation: ##### Cho hai số nguyên `a` và `b`. Yêu cầu: chọn một số nguyên `c` sao cho `a ≤ c ≤ b`, và tính giá trị của biểu thức: `(c - a) + (b - c)` Hãy tìm giá trị nhỏ nhất của biểu thức này. #### Tag ##### `implementation` `*800` `math` <- Đáng lẽ là thế rồi vì đâu cần for loop? Ta chỉ cần `b - a` thôi mà😭 #### AC ![image](https://hackmd.io/_uploads/r13uKzKSlx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, a, b, m = 100; int main() { cin >> t; for (int i = 0; i < t; i++) { m = 1000; cin >> a >> b; for (int i = a; i <= b; i++){if ((i - a) + (b - i) < m){m = (i - a) + (b - i);}} cout << m << "\n"; } return 0; } ``` ::: --- ## 83rd problem :::spoiler ### [1873A - Short Sort](https://codeforces.com/problemset/problem/1873/A) #### Explanation: ##### Cho chuỗi `s` gồm đúng 3 ký tự phân biệt, mỗi ký tự là một trong ba chữ cái `'a'`, `'b'`, `'c'`. Hỏi: có thể biến `s` thành chuỗi `"abc"` bằng **không quá một lần đổi chỗ hai ký tự bất kỳ** không? In ra `YES` nếu có thể, ngược lại in `NO`. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/Bkf_FUtBxx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t; string s; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> s; if (s == "bca" || s == "cab"){cout << "NO\n";} else {cout << "YES\n";} } return 0; } ``` ::: --- ## 84th problem :::spoiler ### [1367A - Short Substrings](https://codeforces.com/problemset/problem/1367/A) #### Explanation: ##### Cho số nguyên `t` (1 ≤ t ≤ 1000) — số lượng test. Mỗi test gồm một chuỗi `s` (2 ≤ |s| ≤ 100, |s| chẵn), được tạo ra bằng cách mã hóa một chuỗi ban đầu `x` theo quy tắc sau: - Ký tự đầu tiên của `x` là `s[0]` - Sau đó, cứ cách 2 ký tự, lấy 1 ký tự của `s` để thêm vào `x` - Ký tự cuối cùng của `x` là ký tự cuối cùng của `s` ##### Hãy khôi phục và in ra chuỗi gốc `x`. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/HJTotvYSee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t; string s; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> s; for (int j = 0; j < s.size()-1; j += 2){cout << s[j];} cout << s[s.size()-1] << "\n"; } return 0; } ``` ::: --- ## 85th problem :::spoiler ### [703A - Mishka and Game](https://codeforces.com/problemset/problem/703/A) #### Explanation: ##### Cho số nguyên `n` (1 ≤ n ≤ 100) — số vòng chơi. Mỗi vòng gồm hai số nguyên `a` và `b` (1 ≤ a, b ≤ 6) — lựa chọn của Mishka và đối thủ. - Nếu `a > b`, Mishka thắng. - Nếu `a < b`, đối thủ thắng. - Nếu `a = b`, vòng đó hòa. ##### In ra tên người thắng nhiều vòng hơn. Nếu bằng nhau, in "Friendship is magic!^^". #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/ByRqhwFHxx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, a, b, ca, cb; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> a >> b; if (a > b){ca++;} else if (a < b){cb++;} } if (ca > cb){cout << "Mishka"; return 0;} else if (ca < cb){cout << "Chris"; return 0;} cout << "Friendship is magic!^^"; return 0; } ``` ::: --- ## 86th problem :::spoiler ### [1950A - Stair, Peak, or Neither?](https://codeforces.com/problemset/problem/1950/A) #### Explanation: ##### Cho ba số nguyên `a`, `b`, `c` (1 ≤ a, b, c ≤ 100). Hãy xác định dãy số `a, b, c` thuộc loại nào trong ba loại sau: - Nếu `a ≤ b ≤ c`, in `"STAIR"`. - Nếu `a < b > c`, in `"PEAK"`. - Ngược lại, in `"NONE"`. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/Hk0hTDKSll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, a, b, c; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> a >> b >> c; if (a < b && b < c){cout << "STAIR\n";} else if (a < b && b > c){cout << "PEAK\n";} else {cout << "NONE\n";} } return 0; } ``` ::: --- ## 87th problem :::spoiler ### [1829A - Love Story](https://codeforces.com/problemset/problem/1829/A) #### Explanation: ##### Cho số nguyên `t` (1 ≤ t ≤ 1000) — số lượng test. Mỗi test gồm một chuỗi `s` có độ dài đúng 10, chỉ gồm chữ cái thường. Hãy đếm số lượng ký tự trong `s` khác với chuỗi `codeforces` tại cùng vị trí. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/rJi_JdtBgx.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, c; string s, a = "codeforces"; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> s; c = 0; for (int j = 0; j < 10; j++){if (a[j] != s[j]){c++;}} cout << c << "\n"; } return 0; } ``` ::: --- ## 88th problem :::spoiler ### [431A - Black Square](https://codeforces.com/problemset/problem/431/A) #### Explanation: ##### Cho bốn số nguyên `a1`, `a2`, `a3`, `a4` (1 ≤ ai ≤ 1000) — số calo tương ứng với các phím `1`, `2`, `3`, `4`. Tiếp theo là một chuỗi `s` chỉ gồm các chữ số `'1'`, `'2'`, `'3'`, `'4'` (1 ≤ |s| ≤ 10⁵), biểu diễn chuỗi các phím được bấm. Tính tổng số calo đã tiêu tốn. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/rJFof_trll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int a, b, c, d, n; string s; int main() { cin >> a >> b >> c >> d >> s; for (char e : s) { if(e == '1'){n += a;} else if(e == '2'){n += b;} else if(e == '3'){n += c;} else if(e == '4'){n += d;} } cout << n; return 0; } ``` ::: --- ## 89th problem :::spoiler ### [1857A - Array Coloring](https://codeforces.com/problemset/problem/1857/A) #### Explanation: ##### Cho `t` testcases, mỗi testcase gồm n phần tử, nếu chia các phần tử ra làm hai phần và tính tổng và nếu chúng đều là số chẵn hoặc số lẻ `YES`, nếu không thì `NO`. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/HyzeXEcBgl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; long long t, n, x, a; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> n; a = 0; for (int j = 0; j < n; j++) { cin >> x; a += x; } if (a % 2 == 0){cout << "YES\n";} else {cout << "NO\n";} } return 0; } ``` ::: --- ## 90th problem :::spoiler ### [80A - Panoramix's Prediction](https://codeforces.com/problemset/problem/80/A) #### Explanation: ##### Cho hai số nguyên `n` và `m`. Kiểm tra xem `m` có phải là số nguyên tố nhỏ nhất đứng ngay sau `n` hay không. Nếu đúng, in ra `YES`, ngược lại in `NO`. Không được có số nguyên tố nào nằm giữa `n` và `m`. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/rJQjPO9reg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; bool prime(int n) { if (n < 2){return false;} if (n == 2 || n == 3){return true;} if (n % 2 == 0 || n % 3 == 0){return false;} for (int i = 5; i * i <= n; i += 6){if (n % i == 0 || n % (i + 2) == 0){return false;}} return true; } int n, m, np; int main() { cin >> n >> m; for (int i = n + 1; i < m; i++){if (prime(i)){cout << "NO"; return 0;}} if (prime(m)){cout << "YES";} else {cout << "NO";} return 0; } ``` ::: --- ## 91st problem :::spoiler ### [1829B - Blank Space](https://codeforces.com/problemset/problem/1829/B) #### Explanation: ##### Cho `t` test, mỗi test gồm một mảng `n` phần tử. Tìm độ dài đoạn liên tiếp các số `0` dài nhất trong mỗi mảng. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/SyalqOcHeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n, x, c, m; int main() { cin >> t; for (int i = 0; i < t; i++) { m = 0; c = 0; cin >> n; for (int j = 0; j < n; j++){cin >> x; if (x == 0){c++; m = max(m,c);} else{c = 0;}} cout << m << endl; } } ``` ::: --- ## 92nd problem :::spoiler ### [1374A - Required Remainder](https://codeforces.com/problemset/problem/1374/A) #### Explanation: ##### Cho `t` test, mỗi test gồm một mảng `n` phần tử. Tìm độ dài đoạn liên tiếp các số `0` dài nhất trong mỗi mảng. #### Tag ##### `implementation` `strings` `*800` #### AC ![image](https://hackmd.io/_uploads/SyalqOcHeg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, x, y, n, m = 0; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> x >> y >> n; int z = (n - y) / x; cout << x * z + y << endl; } } ``` ::: --- ## 93rd problem :::spoiler ### [1370A - Maximum GCD](https://codeforces.com/problemset/problem/1370/A) #### Explanation: ##### Cho số nguyên `n`. Tìm giá trị lớn nhất của `gcd(a, b)` với `1 ≤ a < b ≤ n`. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/rkyYds9reg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> n; cout << n/2 << endl; } } ``` ::: --- ## 94th problem :::spoiler ### [1722A - Spell Check](https://codeforces.com/problemset/problem/1722/A) #### Explanation: ##### Cho chuỗi `s` độ dài `n`. Kiểm tra xem sau khi sắp xếp lại các ký tự, có thể tạo thành chuỗi `"Timur"` hay không. Nếu có, in `YES`, ngược lại in `NO`. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SydKsi5Sge.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n; string x; int main() { cin >> t; string re = "Timru"; for (int i = 0; i < t; i++) { cin >> n; cin >> x; sort(x.begin(), x.end()); if (re == x){cout << "YES\n";} else {cout << "NO\n";} } } ``` ::: --- ## 95th problem :::spoiler ### [1878A - How Much Does Daytona Cost?](https://codeforces.com/problemset/problem/1878/A) #### Explanation: ##### Cho `t` test. Mỗi test gồm `n` số nguyên và một số `k`. Hỏi trong `n` số đó có tồn tại phần tử nào bằng đúng `k` hay không. Nếu có, in `YES`, ngược lại in `NO`. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/SyczI3qSgg.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n, k, x; int main() { cin >> t; for (int i = 0; i < t; i++) { bool found = false; cin >> n >> k; for(int j = 0; j < n; j++){cin >> x; if (x == k){found = true;}} if (found){cout << "YES\n";} else{cout << "NO\n";} } } ``` ::: --- ## 96th problem :::spoiler ### [1433A - Boring Apartments](https://codeforces.com/problemset/problem/1433/A) #### Explanation: ##### Cho số nguyên `n` gồm các chữ số giống nhau, hãy tính tổng số thao tác cần thiết để nhập `n`, giả sử người dùng nhập lần lượt các số có dạng như `1`, `11`, `111`, `1111`, rồi tới `2`, `22`, ..., đến `9`, `9999`, và mỗi chữ số nhập mất 1 thao tác. #### Tag ##### `implementation` `math` `*800` #### AC ![image](https://hackmd.io/_uploads/ryPGh3qSll.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> n; int len = to_string(n).length(); int d = to_string(n)[0] - '0'; cout << (d - 1) * 10 + len * (len + 1) / 2 << endl; } } ``` ::: --- ## 97th problem :::spoiler ### [1703B - ICPC Balloons](https://codeforces.com/problemset/problem/1703/A) #### Explanation: ##### Cho chuỗi `s` gồm `n` ký tự, mỗi ký tự đại diện cho một bài thi ICPC được giải theo thứ tự. Mỗi bài chỉ nhận bóng khi được giải lần đầu, và khi đó sẽ có 2 bóng được phát ra. Những lần sau giải lại bài đó thì không phát thêm bóng. Hỏi sau khi xử lý hết chuỗi, tổng cộng có bao nhiêu bóng được phát ra. #### Tag ##### `implementation` `data` `*800` #### AC ![image](https://hackmd.io/_uploads/BJXnThqree.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t, n; char x; int main() { cin >> t; vector <char> a; set <char> b; for (int i = 0; i < t; i++) { a.clear(); b.clear(); cin >> n; for (int j = 0; j < n; j++){cin >> x; a.push_back(x); b.insert(x);} cout << a.size() + b.size() << endl; } } ``` ::: --- ## 98th problem :::spoiler ### [1619A - Square String?](https://codeforces.com/problemset/problem/1619/A) #### Explanation: ##### Cho chuỗi `s`, hãy kiểm tra xem liệu `s` có thể được tạo bằng cách ghép 2 lần liên tiếp cùng một chuỗi con hay không (tức là `s = t + t` với một chuỗi `t` bất kỳ). #### Tag ##### `implementation` `string` `*800` #### AC ![image](https://hackmd.io/_uploads/Hyi-baqrel.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int t; string x; int main() { cin >> t; for (int i = 0; i < t; i++) { cin >> x; if (x.length() % 2 != 0){cout << "NO\n";} else { if (x.substr(0, x.length()/2) == x.substr(x.length()/2, x.length())){cout << "YES\n";} else {cout << "NO\n";} } } } ``` ::: --- ## 99th problem :::spoiler ### [1791C - Prepend and Append](https://codeforces.com/problemset/problem/1791/C) #### Explanation: ##### Cho số nguyên `t` — số lượng bộ test. Mỗi test gồm một số nguyên `n` và một chuỗi nhị phân `x` có độ dài đúng bằng `n`. Thực hiện nhiều lần nhất có thể thao tác sau: nếu ký tự đầu tiên và ký tự cuối cùng của chuỗi hiện tại khác nhau, xoá cả hai ký tự đó khỏi chuỗi. In ra độ dài của chuỗi sau khi không thể thực hiện thêm thao tác nào nữa. #### Tag ##### `implementation` `two pointers` `*800` #### AC ![image](https://hackmd.io/_uploads/HJgDENsrxl.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, t, c=0; string x; bool no = false, con = true; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> t; c = 0; cin >> x; no = false; con = true; int j = 0, r = t - 1; for (j = 0, r = t-1; j < t; j++, r--) { if (j > r){break;} if (x[j] == x[r]){cout << r - j + 1 << endl; no = true; break;} } if (!no){cout << r - j + 1 << endl;} } return 0; } ``` ::: --- ## 100th problem :::spoiler ### [492A - Vanya and Cubes](https://codeforces.com/problemset/problem/492/A) #### Explanation: ##### Vanya có `n` khối vuông, anh ấy quyết định tạo một kim tự tháp bằng các khối gỗ đó như sau: tầng cao nhất có `1` khối, tầng thứ hai có `1 + 2 = 3` khối, tầng thứ 3 có `1 + 2 + 3 = 6` khối và cứ như vậy trở đi. Tâng thứ `i` phải có `1 + 2 ... + (i - 1) + i` khối. Vanya muốn biết số tầng tối đa anh ấy có thể làm với `n` khối gỗ. #### Tag ##### `implementation` `*800` #### AC ![image](https://hackmd.io/_uploads/By5be9oHee.png) #### Code :::spoiler Code ``` C++ #include <bits/stdc++.h> using namespace std; int n, j = 1; int main() { cin >> n; int used = 0; for (j; ; j++) { for (int i = 1; i <= j; i++){used = i * (i + 1) / 2;} if (used > n) break; n -= used; } cout << j - 1; return 0; } ``` :::