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