码迷,mamicode.com
首页 > 其他好文 > 详细

【习题合集】各种有意义的题目

时间:2019-06-01 23:35:34      阅读:295      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!