#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n, x, y, z;
int price;
while(cin>>n>>x>>y>>z){
bool stop = false;
for(int i=9;i>0;i--){
for(int j=9;j>=0;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;
stop = true;
break;
}
}
if(stop) break;
}
if(!stop){
cout<<'0'<<endl;
}
}
return 0;
}
用一个布尔型变量stop来判断是否找到了合适的解,以决定是否要跳出循环。

京公网安备 11010502036488号