View Code of Problem 609

                    #include <stdio.h>
                    #include <string.h>
                    int main(){
                      char s[1000];
                      int n;
                      while(scanf("%s",s)!=EOF){
                        int len =strlen(s);
                        scanf("%d",&n);
                        int i=0;
                        while(n&&i<len){
                          if(s[i]>s[i+1]){ 
                            s[i]='-1';
                            n--;
                            i=0;
                          }
                          i++;  
                        }
                        for(i=len-1;i>=0;i--){
                          if(s[i]!='-1'){
                            if(n>0){
                              s[i]='-1';
                              n--;
                            }else  break;
                          }
                        }
                        i=0;
                        while(s[i]=='0'||s[i]=='-1'){
                        i++;
                        }
                        if(i<len){
                          while(i<len){
                            if(s[i]!='-1'){
                               printf("%c",s[i]); 
                            }
                            i++;
                          }
                        }else  printf("0");
                        
                        printf("\n");
                      }
                    }

Double click to view unformatted code.


Back to problem 609