提交时间:2021-05-11 17:28:39

运行 ID: 19180

#include<bits/stdc++.h> using namespace std; int UkLock,KLock; int Xarray[10],Yarray[10],Answer[10]; //X-Uklock,Y-Check_Number int Index_X=0; int Maxn_Times=10000; int IsPrime(int Prime){ if(Prime<2) return 0; for(int i=2;i*1<=Prime;i++){ if(Prime%i==0) return 0; } return 1; } void Check(int Check_Number){ int Index_Y,Times=0; memset(Yarray,0,sizeof(Yarray)); while(Check_Number){ Yarray[++Index_Y]=Check_Number%10; Check_Number/=10; } for(int i=1;i<=5;i++){ Times+=min(abs(Yarray[i]-Xarray[i]),abs(10+Xarray[i]-Yarray[i])); } //算拨动次数 min(向上,向下) if(Times>Maxn_Times){ Maxn_Times=Times; for(int i=1;i<=5;i++) Answer[i]=Yarray[i]; } } int main(){ cin>>UkLock; while(UkLock){ Xarray[++Index_X]=UkLock%10; UkLock/=10; } //把每位存储 for(int i=99999;i>=0;i--){ if(IsPrime(i)==0) continue; else Check(i); } //枚举+判断 for(int i=5;i>=1;i--) cout<<Answer[i]; return 0; }