11965 - Extra Spaces

All about problems in Volume 119. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

Re: 11965 - Extra Spaces

Post by unreleased » Fri Feb 13, 2015 4:51 pm

brianfry713 wrote:That is AC code.
aah yeah its AC :o but i can't really remember if i've changed anything in my WA code before posting :roll:

Axiom2277
New poster
Posts: 3
Joined: Mon May 04, 2015 9:02 am

11965 - Extra Spaces

Post by Axiom2277 » Mon May 04, 2015 9:31 am

WHY DO I KEEP GETTING PRESENTATION ERROR?????

Code: Select all

#include <iostream>

using namespace std;

int main()
{
    
    int casess,Lines,x=1; cin >> casess;  cin.ignore();
    string str;
    bool flag3=0;

    while(casess--)
    {
        cin >> Lines;   cin.ignore();
        string s1[Lines];
        str.clear();
        int a=0;
        if(flag3)   cout << endl;   flag3=1;
        cout << "Case " << x++ << ":" << endl;
        while(Lines--)
        {
            bool flag=0,flag2=0;
            getline(cin ,str);
            if(str[str.size()-1]!=' ')
                {   str.insert(str.size()," ");     flag2=1;    }
            if(str.at(0)!=' ')
                {   str.insert(0," ");  flag=1; }
            for(int j=0;j<str.size()-1;j++)
            {
                if(j<str.size()-1 && j>0 && str.at(j)==' ' && (str.at(j+1)==' ' || str.at(j-1)==' '))
                {
                    str.erase(j,1);     j=0;
                }
            }
            if(flag2==1)
                str.erase(str.size()-1,1);
            if(flag==1)
                str.erase(0,1);
            cout << str << endl;
        }
    }
}
Last edited by brianfry713 on Fri Jun 19, 2015 7:08 am, edited 1 time in total.
Reason: Added code blocks

Post Reply

Return to “Volume 119 (11900-11999)”