UVa 12290 - Counting Game

UVA - 12290


#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

bool is7(int n) {
	stringstream ss;
	ss << n;
	string s = ss.str();
	if (s.find("7") == s.npos) {
		if (n % 7 == 0) return true;
		return false;
	}
	return true;
}

int main(void) {
	int n, m, k;
	int num, cnt, per;
	bool f;
	while (cin >> n >> m >> k) {
		if (n == 0 && m == 0 && k == 0) break;
		num = 1;
		cnt = 0;
		per = 1;
		while (true) {
			if (per == 1) f = true;
			else if (per == n) f = false;
			if (is7(num) && per == m) cnt++;
			if (cnt == k) {
				cout << num << endl;
				break;
			}
			if (f) per++;
			else per--;
			num++;
		}
	}
	return 0;
}


你可能感兴趣的:(UVa 12290 - Counting Game)