TOPIC

5% Wrong Answer

hart asked 1 year ago

#include <iostream>
using namespace std;
int main(){

int op;
string palavra;

cin>>op;
cin.ignore();
while(op--){

getline(cin, palavra);

    if(palavra[0]!=32){
        cout<<palavra[0];
    }

    for(int i=0;i<palavra.size();i++){
        if(palavra[i]==32 && palavra[i+1]!=32){

            cout<<palavra[i+1];
        }
}

cout<<endl;

}
    return 1;
}

I tested this on uDebu gand even there all seemed correct. Anyone?

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

  • feodorv replied 1 year ago

    for(int i=0;i<palavra.size();i++){
            if(palavra[i]==32 && palavra[i+1]!=32){

    If i == palavra.size()-1 then you have palavra[palavra.size()] which is out of string bounds.