#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
}
}
}
算法学习-day1
于 2023-01-07 17:35:04 首次发布