TOPIC

100% wrong c++ why?

Dusan Vidojevic asked 1 year ago

include<bits/stdc++.h>

using namespace std;

int main () { int n=0; char a[100000],char_array[100000]; string s[100000]; while((a[n]!='0'||s[n]!="0")||n==0) { cin>>a[n]>>s[n]; if(a[n]=='0'&&s[n]=="0") break; n++; } for(int i=0;i<n;i++) { strcpy(char_array,s[i].c_str()); for(int j=0;j<s[i].length();j++) { if(char_array[j]==a[i]) char_array[j]='~'; } for(int j=0;j<s[i].length();j++) { if(j==0) { while(char_array[j]=='~'||char_array[j]=='0') { j++; if(j==s[i].length()-1) cout<<0; } } if(char_array[j]!='~') cout<<char_array[j]; } if(i!=n-1) cout<<endl; } return 0; }

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 1 year ago

    Awful mess for reading input code. Why not simply

    char  s[1024];
    int d;
    while( scanf( "%d %s", &d, s) == 2 && d > 0 )
    {
      ...
    }