题解 | Old Bill
#include <iostream> using namespace std; int max(int a,int b) { if(a<b){ return b; } else return a; } int main() { int a,b,c,d,e,n; int s1,s2; int key,remain,Max=0; cin>>n; cin>>b>>c>>d; for(a=0;a<=9;a++){ for(e=0;e<=9;e++){ key=a*10000+b*1000+c*100+d*10+e; remain=key/n; if((key%n==0)&&remain!=0&&remain>Max){ s1=a; s2=e; Max=max(Max,remain); } } } if(Max!=0&&s1!=0){ cout<<s1<<" "<<s2<<" "<<Max<<endl; } else { cout<<"0"<<endl; } return 0; }