题解 | #Old Bill#

Old Bill

https://www.nowcoder.com/practice/17a30153e092493e8b4d13f321343927

#include <iostream>
using namespace std;

int main() {
    int a, b;
    int n,x,y,z;
    int price=0;
    int flag=1;
    while (cin >>n>>x>>y>>z) { // 注意 while 处理多个 
        flag=1;
        for(a=9;a>0&&flag==1;a--)
        {
            for(b=9;b>=0&&flag==1;b--)
            {
                price=0;
                if((a*10000+x*1000+y*100+z*10+b)%n==0)
                {
                    price=(a*10000+x*1000+y*100+z*10+b)/n;
                    cout<<a<<" "<<b<<" "<<price<<endl;                 
                }
                if(price!=0)flag=0;
            }
            
        }
        if(price==0)cout<<"0"<<endl;

    }
}
// 使用状态标志位flag巧妙设计跳出双重循环

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 11:30
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务