UVa12290 Counting Game

解法
FizzBuzz系の問題

#include <bits/stdc++.h>
using namespace std;

inline bool inDigit7(int cnt) {
  stringstream ss; ss<<cnt;
  return ss.str().find('7') != string::npos;
}

int main() {
  
  int N, M, K;
  while(cin >> N >> M >> K && (N|M|K)) {
    int k = 0, cnt = 0;
    bool S = 1;
    while(1) {
      for(int m=(S?1:N-1); (S?m<=N:m>=2); (S?m++:m--)) {
	cnt++;
	if((cnt % 7 == 0 || inDigit7(cnt)) && m == M) { k ++; }
	if(k == K) {
	  cout << cnt << endl;
	  goto EXIT;
	}
      }
      S = !S;
    }
  EXIT:;
  }
  
  return 0;
}