提交时间:2024-02-22 21:00:23

运行 ID: 41658

#include<bits/stdc++.h> using namespace std; int main() { int n,c=-1; bool flag=true; char m[100],dm[100],ds[1000],s[1000]; cin>>n; gets(m); for(int i=1; ;i++){ for(int j=c;j>=0;j--){ dm[c-j]=m[j]; } for(int j=c;j>=0;j--){ s[j]=dm[j]+m[j]; if(s[j]>=n){ s[j]-=n; s[j-1]++; } } for(int j=c+1;j>=0;j--){ if(j==0&&s[j]==0){ break; } ds[c-j]=s[j]; } for(int j=c;j>=0;j--){ if(dm[j]!=s[j]) flag=false; } if(flag==false) continue; else if(flag==true&&i>=30){ cout<<"Impossible!"; return 0; } else{ cout<<"STEP="<<i; return 0; } } }