Showing posts with label loop. Show all posts
Showing posts with label loop. 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. 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. }