题目描述
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
解题思路
代码
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 char s[200010][10]; 7 int n; 8 inline bool jud(char* a,char* b,int now,int len){ 9 if(now>=len)return 0; 10 if(b[now]!='?'){ 11 if(a[now]==b[now])return jud(a,b,now+1,len); 12 else return a[now]<b[now]; 13 } 14 else { 15 b[now]=a[now]; 16 if(jud(a,b,now+1,len))return 1; 17 if(b[now]!='9'){b[now]++; return 1;} 18 b[now]='?'; return 0; 19 } 20 } 21 int main(){ 22 scanf("%d",&n); 23 for(register int i=1;i<=n;i++){ 24 scanf("%s",s[i]); 25 } 26 s[0][0]='0'; 27 for(register int i=1;i<=n;i++){ 28 int l1=strlen(s[i-1]),l2=strlen(s[i]); 29 if(l1>l2){ 30 cout<<"NO"<<endl; 31 return 0; 32 } 33 if(l1==l2&&jud(s[i-1],s[i],0,l1)==0){ 34 cout<<"NO"<<endl; 35 return 0; 36 } 37 for(register int j=0;j<l2;j++){ 38 if(s[i][j]=='?'){ 39 if(j)s[i][j]='0'; 40 else s[i][j]='1'; 41 } 42 } 43 } 44 cout<<"YES"<<endl; 45 for(register int i=1;i<=n;i++){ 46 printf("%s\n",s[i]); 47 } 48 }