标签:nis des answer ifd stream oca ++ 意义 fine
**1.
# include <iostream> # define LOCAL using namespace std; int main(){ /* # ifdef LOCAL freopen("C:\\Users\\Administrator\\Desktop\\新建文本文档.txt", "r", stdin); freopen("C:\\Users\\Administrator\\Desktop\\新建文本文档2.txt", "w", stdout); # endif */ int a, b, c, flag = 0, count = 0; while(cin >> a >> b >> c){ count++; flag = 0; for(int i = 0; i < 34; i++){ int num = 3 * i + a; if(num % 5 == b && num % 7 == c && num >0 && num < 100){ cout << "Case " << count << ": " << num << endl; flag = 1; } } if(!flag) cout << "Case " << count << ": " << "NO answer!" << endl; } }
**2.习题2-6 排列( permutation)
用1, 2, 3, …, 9组成3个三位数abc, def和ghi, 每个数字恰好使用一次, 要
求abc: def: ghi= 1: 2: 3。 按照“abc def ghi”的格式输出所有解, 每行一个解。
# include <iostream> using namespace std; void Judge(int array[], int num){ int a = num % 10, b = num / 10 % 10, c = num / 100; array[a]++; array[b]++; array[c]++; } int main(){ for(int i = 100; i < 334; i++){ int a[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int abc = i * 1, def = i * 2, ghi = i * 3, j; Judge(a, abc); Judge(a, def); Judge(a, ghi); for(j = 1; j < 10; j++){ if(a[j] != 1 || a[0] != 0) break; } if(j == 10){ cout << abc << ‘ ‘ << def << ‘ ‘ << ghi << endl; } } }
标签:nis des answer ifd stream oca ++ 意义 fine
原文地址:https://www.cnblogs.com/phemiku/p/10961238.html