题解 第二章暴力求解| #Old Bill#

Old Bill

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

//Total number of turkeys is N
//Between 1 to 99
//Total price have 5 digits, only know the middle 3
//All turkeys same price, the price is integer
#include <stdio.h>
int main()
{
    int n,x,y,z;
    int a,b;
    while(scanf("%d%d%d%d",&n,&x,&y,&z)!=EOF)
    {
        int findOrNot=0;
        for(a=9;a>=1;a--)
        {
            for(b=9;b>=0;b--)
            {
                int temp=a*10000+x*1000+y*100+z*10+b;
                if(temp%n==0)
                {
                    findOrNot=1;
                    printf("%d %d %d\n",a,b,temp/n);
                    break;
                }
            }
            if(findOrNot==1)
                break;
        }
        if(findOrNot==0)
            printf("0\n");
    }
    return 0;
}
//Total number of turkeys is N
//Between 1 to 99
//Total price have 5 digits, only know the middle 3
//All turkeys same price, the price is integer
#include <iostream>
using namespace std;
int main()
{
    int n,x,y,z;
    int a,b;
    while(cin>>n>>x>>y>>z)
    {
        int findOrNot=0;
        for(a=9;a>=1;a--)
        {
            for(b=9;b>=0;b--)
            {
                int temp=a*10000+x*1000+y*100+z*10+b;
                if(temp%n==0)
                {
                    findOrNot=1;
                    cout<<a<<" "<<b<<" "<<temp/n<<"\n";
                    break;
                }
            }
            if(findOrNot==1)
                break;
        }
        if(findOrNot==0)
            cout<<0<<"\n";
    }
    return 0;
}
王道机试指南刷题 文章被收录于专栏

计划刷完这本书

全部评论

相关推荐

程序员猪皮:看不到八股什么意思
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务