算法学习-day1

#include<iostream>
#include<cstdio>
#include <iterator>

using namespace std;

    
    //求反序数
    int Reverse(int x){
        int recv = 0;
        while(x != 0){
            recv *= 10;
            recv += x%10;
            x /= 10;
        }
        return recv;
    }


// int a =10;
int main(){
    // cout << "hello world";
    // int a=0;
    // printf("a=%d",::a);
    // for(int a=0;a<=9;a++)
    //     for(int b=0;b<=9;b++)
    //         for(int c=0;c<=9;c++)
    //             for(int d=0;d<=9;d++)
    //                 if(1000*a+100*b+10*c+d==1000*d+100*c+10*b+a)
    //                     printf("%d%d%d%d\n",a,b,c,d);

    // int a,b;
    // cin >> a >> b;
    // cout << a + b <<endl;
    // return 0;

    // int a,b;
    // while(cin >> a >> b){
    //     cout << a+b <<endl;

    // }

    //多组样例输入且有条件
    // int a,b;
    // while(cin >> a >> b){
    //     if(a == 0 && b==0){
    //         break;
    //     }
    //     cout << a + b <<endl;
    
    // }

    //图形排版
    //1
    // int h;
    // cin >> h;
    // for(int i=0;i<h;i++){
    //     for(int j=0;j<i + h;j++){
    //         cout << "*";
    //     }
    //     cout << endl;
    // }

    
    // for(int i = 1000;i<10000;i++){
    //     if(i * 9 == Reverse(i)){
    //         cout << i <<endl;
    //     }
    // }

    //对称平方数
    // for(int i=1;i<256;i++){
    //     if(i * i == Reverse(i * i)){
    //         cout << i << endl;
    //     }
    // }

    //与7无关的数
    // int n;
    // int sum = 0;
    // cin >> n;
    
    // for(int i = 0;i <= n;i++){
    //     if(i%7!=0 && i%10!=7 && i/100!=7 && i%100/10!=7){
    //         sum += i * i;
    //     }
    // }
    // cout << sum;

    //百鸡问题
    // int money;
    // cin >>money;
    // for(int x = 0;x <= 20;x++){
    //     for(int y = 0;y <= 33;y++){
    //         for(int z = 0;z <= 300;z++){
    //             if(x * 5 + y * 3 + z *1/3 == money){
    //                 cout << x <<" "<< y <<" "<< z <<endl;
    //             }
    //         }
    //     }         
    // }

    //Old Bill(上交复试题)
    // int N,X,Y,Z,a,b;
    // int sum = 0;
    // int max = 0;
    // cin >> N;
    // while(cin >> X >> Y >> Z){
    //     for(int i = 9;i>1;i--){
    //         for(int j = 9;j >= 0;j--){
    //             sum = i*10000+X*1000+Y*100+Z*10+j;
    //             if(sum%N == 0 && N > max){
    //                 max = sum/N;
    //                 cout << a <<" "<< b <<" "<< max <<endl;
    //                 i = -1;
    //                 j = -1;
    //             }

    //         }
    //     }
    //     // cout << a <<" "<< b <<" "<< max <<endl;
    // } 
    

    int n,x,y,z;
    int price=0;    //要输出的单价 
    while(cin>>n>>x>>y>>z){
        for(int i=1;i<9;i++){    //i是最高位,j是最低位,分别从9往下循环 
            for(int j=0;j<=9;j++){
                if((i*10000+x*1000+y*100+z*10+j)%n==0){//确保单价是整数 
                    price=(i*10000+x*1000+y*100+z*10+j)/n;
                    cout<<i<<' '<<j<<' '<<price<<endl;
                    i=-1;    //因为输出的一定是最大值,因此设置-1跳出循环 
                    j=-1;
                    price=0;    //并设置单价归0 
                }
                if(i==1&&j==0) cout<<0<<endl;    // 如果找不到任何一组满足要求的就输出0 
            }
        }
    } 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值