zoukankan      html  css  js  c++  java
  • [C++]2-2 韩信点兵

    /*
        韩信点兵
        相传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排、五人一排、七人一排地变换队
        形,而他每次只掠一眼队伍的排尾就知道总人数了。输入多组数据,每组数据包含3个非负整数a,b,c,表示每种
        队形排尾的人数(a<3,b<5,c<7),输出总人数的最小值(或报告无解)。已知总人数不小于10,不超过100.输入
        到文件结束为止。
    */
    # define LOCAL
    #include<stdio.h>
    #include<time.h>
    
    int main(){
    #ifdef LOCAL
        freopen("data.in","r", stdin);
        freopen("data.out","w", stdout);
    #endif // LOCAL
    
        int a, b, c;
        int peoples, cases=0;
        while(scanf("%d %d %d", &a, &b, &c) == 3){
            cases++;
    
            peoples = -1;
            for(int i = 10; i < 100; i++){
                if((i % 3 == a) && (i % 5 == b) && (i % 7 == c)){
                    peoples = i;
                }
            }
            if(peoples > 0){
                 printf("Case %d: %d
    ", cases, peoples);
            } else {
                printf("Case %d: No Answer
    ", cases);
            }
        }
    
        return 0;
    }
    /*
    [input]
    2 1 6
    2 1 3
    
    [output]
    Case 1: 41
    Case 2: No Answer
    */
    

    【参考文献】

      刘汝佳.《算法竞赛入门经典》

     

  • 相关阅读:
    关于++i和i++的左值、右值问题
    运算符优先级
    计算机中的数及其编码
    递归函数
    PHP读取excel(4)
    替换元素节点replaceChild()
    子结点childNodes
    插入节点insertBefore()
    创建节点createElement
    插入节点appendChild()
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/9067146.html
Copyright © 2011-2022 走看看