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

iriz7482
New poster
Posts: 15
Joined: Mon Apr 04, 2011 3:18 pm

11965 - Extra Spaces

Post by iriz7482 » Mon Apr 11, 2011 5:04 pm

I've got W.A on this problem no matter how I fixed my code :oops: . Please help me

Code: Select all

remove after A.C :D
always have problems with string processing... :-?
Last edited by iriz7482 on Mon Apr 11, 2011 7:56 pm, edited 1 time in total.

yan yan
New poster
Posts: 13
Joined: Thu May 13, 2010 4:16 pm
Location: Viet Nam
Contact:

Re: 11965 - Extra Spaces

Post by yan yan » Mon Apr 11, 2011 7:18 pm

first, you must

Code: Select all

scanf("%d",&k);getchar();
indeed

Code: Select all

scanf("%d\n",&k);
second, the last character can be space. It's possible :)

iriz7482
New poster
Posts: 15
Joined: Mon Apr 04, 2011 3:18 pm

Re: 11965 - Extra Spaces

Post by iriz7482 » Mon Apr 11, 2011 7:53 pm

yan yan wrote:first, you must

Code: Select all

scanf("%d",&k);getchar();
indeed

Code: Select all

scanf("%d\n",&k);
second, the last character can be space. It's possible :)
Thank you very much, I got A.C :D
anyway, I tried to use fflush(stdin) instead of getchar() but it didn't work :-?

sss0905063
New poster
Posts: 2
Joined: Sun Jun 05, 2011 1:05 am

Re: 11965 - Extra Spaces

Post by sss0905063 » Sun Jun 05, 2011 1:11 am

WHY WA?? here is my code-

removed after AC
Last edited by sss0905063 on Sun Jun 05, 2011 12:44 pm, edited 1 time in total.

robot
New poster
Posts: 29
Joined: Sun May 24, 2009 8:39 pm

Re: 11965 - Extra Spaces

Post by robot » Sun Jun 05, 2011 10:03 am

Hi SS....
you have a simple mistake..The problem says print a blank line between test case but not at all..your program print always a blank line.
try this case:
2
1
<space><space>
1
<space><space>i am a student.
output:
Case 1:
<space>
Case 2:
<space>i am a student.
ASU(SUST)

sss0905063
New poster
Posts: 2
Joined: Sun Jun 05, 2011 1:05 am

Re: 11965 - Extra Spaces

Post by sss0905063 » Sun Jun 05, 2011 12:42 pm

thanx robot bro.got AC. sometimes silly mistakes make it more than worst.

rahian
New poster
Posts: 5
Joined: Wed Jul 30, 2008 3:27 am
Location: CUET
Contact:

Re: 11965 - Extra Spaces

Post by rahian » Wed Aug 17, 2011 12:37 am

I got Accepted for this problem but i would like to know something more:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
long t,n,i,cas,j,f=0,ln,ff;

freopen("in.txt","r",stdin);
while(cin>>t)
{
cas=0;
while(t)
{
cin>>n;
getchar();
if(f)
cout<<endl;
f=1;
cout<<"Case "<<++cas<<":"<<endl;

while(n)
{
j=i=0;

string line,line2;
getline(cin,line);
//getchar();
ln=line.length();
//cout<<ln<<endl;
while(ln>=i)
{
ff=0;
line2[j++]=line;

if(line==' ')
{
while(line==' ')
i++;
ff=1;
}
if(ff==0)
i++;
}
line2[j-1]='\0';
//cout<<line2<<endl;
for(i=0;i<j-1;i++)
putchar(line2);
cout<<endl;
//puts(line2);
line.clear();
line2.clear();
n--;
}
t--;
}

}
return 0;
}
>> here //cout<<line2<<endl;// doe's not work but when i use:
for(i=0;i<j-1;i++)
putchar(line2);
it has work and got AC, I got accepted by using another way but this //cout<<line2<<endl;// statement is not working
why???????

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11965 - Extra Spaces

Post by Hasselli » Sat Apr 21, 2012 8:49 pm

Code: Select all

procedure Shift(var s: string; ind: Integer);
var
  i: Integer;

begin
  for i := ind to length(s) do
    s[i] := s[i + 1];
  setlength(s, length(s) - 1);
end;

var
  i, j, t, tt, n: Integer;
  s: string;

begin
  Readln(t);
  for tt := 1 to t do
  begin
    Readln(n);
    Writeln('Case ', tt, ':');
    for i := 1 to n do
    begin
      Readln(s);
      for j := 1 to Length(s) do
        While (s[j] = ' ') and (s[j + 1] = ' ') do
          Shift(s, j);
      Writeln(s);
    end;
  end;
end.
Why it is wrong?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11965 - Extra Spaces

Post by brianfry713 » Mon Apr 23, 2012 11:21 pm

The output should have a blank line between cases.
Check input and AC output for thousands of problems on uDebug!

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11965 - Extra Spaces

Post by Hasselli » Tue Apr 24, 2012 6:34 pm

Code: Select all

procedure Shift(var s: string; ind: Integer);
var
  i: Integer;

begin
  for i := ind to length(s) do
    s[i] := s[i + 1];
  setlength(s, length(s) - 1);
end;

var
  i, j, t, tt, n: Integer;
  s: string;

begin
  Readln(t);
  for tt := 1 to t do
  begin
    Readln(n);
    Writeln('Case ', tt, ':');
    for i := 1 to n do
    begin
      Readln(s);
      for j := 1 to Length(s) do
        While (s[j] = ' ') and (s[j + 1] = ' ') do
          Shift(s, j);
      Writeln(s);
    end;
    Writeln;
  end;
end.
How about this?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11965 - Extra Spaces

Post by brianfry713 » Wed Apr 25, 2012 1:14 am

Don't print an extra newline at the end.
Check input and AC output for thousands of problems on uDebug!

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11965 - Extra Spaces

Post by Hasselli » Wed Apr 25, 2012 5:54 pm

Code: Select all

procedure Shift(var s: string; ind: Integer);
var
  i: Integer;

begin
  for i := ind to length(s) do
    s[i] := s[i + 1];
  setlength(s, length(s) - 1);
end;

var
  i, j, t, tt, n: Integer;
  s: string;

begin
  Readln(t);
  for tt := 1 to t do
  begin
    Readln(n);
    Writeln('Case ', tt, ':');
    for i := 1 to n do
    begin
      Readln(s);
      for j := 1 to Length(s) do
        While (s[j] = ' ') and (s[j + 1] = ' ') do
          Shift(s, j);
      Writeln(s);
    end;
    if tt < t then
	Writeln;
  end;
end.
And this?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11965 - Extra Spaces

Post by brianfry713 » Thu Apr 26, 2012 4:51 am

I believe your problem is that a Pascal string only holds up to 256 characters and a line might be up to 500 characters.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11965 - Extra Spaces

Post by brianfry713 » Thu Apr 26, 2012 7:59 am

Input:

Code: Select all

1
1
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Output should be:

Code: Select all

012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Check input and AC output for thousands of problems on uDebug!

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11965 - Extra Spaces

Post by Hasselli » Fri Apr 27, 2012 9:08 am

brianfry713 wrote:Input:

Code: Select all

1
1
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Output should be:

Code: Select all

012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Output is right.

Post Reply

Return to “Volume 119 (11900-11999)”