落書きノート

ふと自分が気になった事を書いてます

C++で問題を解く AIZU ONLINE JUDGE

// Print a Chessboard

#include <iostream>

using namespace std;

int main(void) {
  int H,W;
  while(cin >> H >> W && H && W) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(i % 2 == 0 && j % 2 == 0)
          cout << "#";
        else if(i % 2 == 1 && j % 2 == 0)
          cout << ".";
        else if(i % 2 == 0 && j % 2 == 1)
          cout << ".";
        else
          cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

// Structured Programming

#include <iostream>

using namespace std;

int main(void) {
  int i = 0;
  int n;
  cin >> n;
  while(++i <= n) {
    int x = i;
    if(x % 3 == 0) {
      cout << " " << i;
      if(i <= n) continue;
    }
    while(x) {
      if(x % 10 == 3) {
        cout << " " << i;
        if(i <= n) break;
      }
      x /= 10;
    }
  }
  cout << endl;
  return 0;
}