Showing posts with label Codeforce. Show all posts
Showing posts with label Codeforce. Show all posts

Monday, September 16, 2019

Codeforce A. DZY Loves Chessboard

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main(){
  4. int n, m, b = 0, w = 0;
  5. cin >> n >> m;
  6. char data[n][m];
  7. for(int i = 0; i < n; i++) {
  8. for(int j = 0; j < m; j++) {
  9. cin >> data[i][j];
  10. }
  11. }
  12. for(int i = 0; i < n; i++) {
  13. for(int j = 0; j < m; j++) {
  14. if(data[i][j] == '.') {
  15. if((i+j) % 2) cout << 'W';
  16. else cout << 'B';
  17. }else cout << data[i][j];
  18. }
  19. cout << endl;
  20. }
  21. return 0;
  22. }

Codeforce A. Middle of the Contest

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main(){
  4. int h1, m1, h2, m2, ans = 0, resH = 0, resM = 0, rM;
  5. scanf("%d:%d", &h1, &m1);
  6. scanf("%d:%d", &h2, &m2);
  7. if(m1 > m2) ans = (60 - m1) + m2;
  8. else ans = (h2 - h1)*60 + (m2-m1);
  9. ans /= 2;
  10. resH = h1 + ans/60;
  11. rM = m1 + ans%60;
  12. if( rM / 60 > 0) resH += rM / 60;
  13. resM = rM%60;
  14. if(resH < 10) cout <<0;
  15. cout << resH << ":";
  16. if(resM < 10) cout << 0;
  17. cout << resM << endl;
  18. return 0;
  19. }

Codeforce A. Life Without Zeros

  1. #include< iostream >
  2. using namespace std;
  3. int withOutZero(int n){
  4. int ans = 0;
  5. while(n != 0) {
  6. if(n%10 != 0)
  7. ans = n%10 + (ans *10) ;
  8. n /= 10;
  9. }
  10. return ans;
  11. }
  12. int main(){
  13. int n, m;
  14. cin >> n >> m;
  15. if(n == m) return cout << "YES" << endl, 0;
  16. int ans = n+m;
  17. ans = withOutZero(ans);
  18. ans = withOutZero(ans);
  19. n = withOutZero(n);
  20. n = withOutZero(n);
  21. m = withOutZero(m);
  22. m = withOutZero(m);
  23. if(ans == n+m) cout << "YES" << endl;
  24. else cout << "NO" << endl;
  25. return 0;
  26. }

Codeforce A. Yaroslav and Permutations

  1. #include< iostream >
  2. using namespace std;
  3. int main() {
  4. int n, x;
  5. cin >> n;
  6. int ar[10001] = {0};
  7. for(int i = 0; i < n; i++) {
  8. cin >> x;
  9. ar[x]++;
  10. if(ar[x] > (n+1)/2) return cout << "NO\n", 0;
  11. }
  12. cout << "YES\n";
  13. return 0;
  14. }

Codeforce A. Collecting Beats is Fun

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main(){
  4. int k;
  5. char a;
  6. cin >> k;
  7. int ar[10] = {0};
  8. for(int i = 0; i < 16; i++){
  9. cin >> a;
  10. ar[a]++;
  11. }
  12. for(int i = 1; i < 10; i++)
  13. if(ar[i+'0'] > 2*k) return cout << "NO\n", 0;
  14. cout << "YES\n";
  15. return 0;
  16. }

Codeforce A. Levko and Table

  1. #include< iostream >
  2. using namespace std;
  3. int main()
  4. {
  5. int n, k;
  6. cin >> n >> k;
  7. for(int i = 0; i < n; i++) {
  8. for(int j = 0; j < n; j++) {
  9. cout << ((i == j)? k : 0 ) << " ";
  10. }
  11. cout << endl;
  12. }
  13. return 0;
  14. }

Codeforce A. Vasya and Digital Root

  1. #include< iostream >
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int k, d;
  7. cin >> k >> d;
  8. if(d == 0 and k > 1) return cout << "No solution\n", 0;
  9. cout << d ;
  10. while(--k) cout << 0 ;
  11. return 0;
  12. }

Codeforce A. Two Bags of Potatoes

  1. #include< iostream >
  2. using namespace std;
  3. int main()
  4. {
  5. int y, k, n;
  6. cin >> y >> k >> n;
  7. int x = k - y%k;
  8. if(x+y > n) return cout << -1 << endl , 0;
  9. for(int i = x ; i <= n-y; i+=k)
  10. cout << i << " ";
  11. return 0;
  12. }

Codeforce A. The Child and Homework

  1. #include< iostream >
  2. #include< cstdio >
  3. #include< algorithm >
  4.  
  5. using namespace std;
  6.  
  7. string o[4];
  8.  
  9. int main() {
  10.  
  11. int maxlength = 0, minlength = 110, maxindex = 0, minindex = 0;
  12.  
  13. int c[4];
  14.  
  15. for (int i = 0; i < 4; i++) {
  16. getline(cin, o[i]);
  17. c[i] = o[i].length() - 2;
  18. }
  19.  
  20. sort(c, c + 4);
  21.  
  22. bool hasMax = c[3] >= c[2] * 2;
  23. bool hasMin = c[0] <= c[1] / 2;
  24.  
  25. if (hasMax == hasMin) {
  26. cout << "C";
  27. } else if (hasMin) {
  28. for (int i = 0; i < 4; i++) {
  29. if (c[0] + 2 == o[i].length()) {
  30. cout << o[i].at(0);
  31. }
  32. }
  33. } else if (hasMax) {
  34. for (int i = 0; i < 4; i++) {
  35. if (c[3] + 2 == o[i].length()) {
  36. cout << o[i].at(0);
  37. }
  38. }
  39. }
  40.  
  41. return 0;
  42. }

Codeforce A. Soroban

    1. #include < bits/stdc++.h >
    2. using namespace std;
    3. int main()
    4. {
    5. int n;
    6. cin>>n;
    7. if(!n){
    8. cout<<"O-|-OOOO\n";
    9. return 0;
    10. }
    11. while(n){
    12. int m=n%10;
    13. n/=10;
    14. string s="--|OOOOO";
    15. if(m>=5)s[1]='O';
    16. else s[0]='O';
    17. s[m%5+3]='-';
    18. cout<<s<<endl;
    19. }
    20. }