483 - Word Scramble

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

Moderator: Board moderators

Post Reply
Bluefin
New poster
Posts: 20
Joined: Sat Jul 08, 2006 3:39 pm
Contact:

Post by Bluefin » Wed Aug 16, 2006 3:42 pm

I just solved this problem today ~~
I didn't read your code but I compared the output from your program with
my ACC one.

my output is

Code: Select all

I evol .uoy
uoY evol .em
er'eW a yppah .ylimaf
while yours is

Code: Select all

I evol .uoy
uoY evol .em
er'eW a yppah .ylimaf
-----------> there is a blank line
But this may only cause PE ~~
But I tell you so once you get rid of WA you can get ACC without PE

BTW I use getchar to solve this problem in 0.000 second!!
If you want to try a different approach, that's the way!!

Hope this will help you ~~ :D

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Wed Aug 16, 2006 5:18 pm

I have modified your code a bit... it is AC now... Here it is :

Code: Select all

#include <string> 
#include <cstring> 
#include <iostream> 
//#include <fstream> 
#include <stack> 
using namespace std; 

int main() 
{ 
//   ifstream fin("input.txt"); 
   stack<char> stk; 
   string str; 
   int count = 0;
   while (getline(cin, str)) { 
         if (count) cout << "\n";
      for (int i  = 0; i < str.length(); i++) { 
         if (str[i] != ' ') { 
            stk.push(str[i]); 
         } 
         else { 
            while (!stk.empty()) { 
               cout << stk.top(); 
               stk.pop(); 
            } 
            if (str[i] == ' ') 
               cout << ' '; 
         }
         count++;
      } 
      while (!stk.empty()) {
            cout << stk.top();
            stk.pop();
      }
   } 
   return 0; 
}

Iffat
New poster
Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

483...why presentation error?

Post by Iffat » Wed Aug 23, 2006 4:46 pm

:oops: i can't understant why i got presentation error....

Code: Select all

c#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 50000

int main()
{
	long i,j,l,n;
	char ch,str[MAX],str1[MAX];
	
	while(scanf("%s",&str)!=EOF)
	{
		l=strlen(str);
		for(i=0,j=l-1;i<l,j>=0;i++,j--)
			{
				str1[i]=str[j];
						
			}
			
		printf("%s",str1);
		scanf("%c",&ch);
		printf("%c",ch);
		for(n=0;n<l;n++)str1[n]='\0';
		
			
	}
	
				
	
	return 0;
}
plzz help me :(

clove
New poster
Posts: 1
Joined: Wed Aug 23, 2006 1:52 pm

483 ?? Wrong Answer.. help me!!

Post by clove » Thu Aug 24, 2006 4:59 am

it's my code.
it code Wrong Answer..

[483] tab key application??

#include<stdio.h>
#include<string.h>

void main()
{
char a[100000];
int temp[100000];

int ns;
int count;
int i,j;

while( gets(a) != NULL )
{

ns = strlen(a);

count = 1;

temp[0] = 0;

for( i = 0 ; i <=ns ; i++ )
if( a[i]==' ' || a[i]=='\0')
{


temp[count] = i;

count=count-1;


if( count==0 )

{
for( j = i-1 ; j >= temp[count] ; j-- )

printf("%c",a[j]);

count=count+2;
}
else
{
for( j= i ; j > temp[count] ; j-- )

printf("%c",a[j]) ;

count=count+2;

}


}

printf("\n");
}
}

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja » Wed Feb 14, 2007 4:12 am

You must remove only last blanks, and other blanks must same as input string.

For example,

Input ( _ means blank )

Code: Select all

__I___love_you.___ 
Presentation Error

Code: Select all

__I___evol_.uoy___ 
Accepted

Code: Select all

__I___evol_.uoy
Good luck.
I love Problem Solving!!! :) :) :)

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja » Wed Feb 14, 2007 4:19 am

Your progam prints wrong blanks...
You must remove only last blanks, and other blanks must same as input string.

For example,

Input ( _ means blank )

Code: Select all

__I___love_you.___ 
Presentation Error

Code: Select all

__I___evol_.uoy___ 
Accepted

Code: Select all

__I___evol_.uoy
Good luck.
I love Problem Solving!!! :) :) :)

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

why PE?()483

Post by ishtiaq ahmed » Tue Feb 20, 2007 2:27 pm

I cannot understand why this easy problem hangs me on presentation error? Can anybody help me?plzzzzzzzzz

Code: Select all

The code is removed after AC.
Last edited by ishtiaq ahmed on Sat Feb 24, 2007 6:09 am, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Feb 22, 2007 2:49 pm

soyoja wrote:You must remove only last blanks, and other blanks must same as input string.
For the
Input:

Code: Select all

__I___love_you.___ 
My accepted code returns
Output:

Code: Select all

__I___evol_.uoy___
So trailing blanks may not be the actual problem.
Ami ekhono shopno dekhi...
HomePage

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

message of 383

Post by ishtiaq ahmed » Sat Feb 24, 2007 6:08 am

thank you Mr.Jan.I got AC. :P
No venture no gain

with best regards
------------------------
ishtiaq ahmed

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

483 Word Scramble PE!!!!!!!!!!!!!

Post by x140l31 » Tue Feb 27, 2007 2:34 am

I don't know why I have PE.

I tried all the possibilities that I found in the forum... removing the lasts blanks... without removing them... removing the last blank line...

I need help please :(

Can someone give me an input sample or send me a mp with the correct code in C++? :(

thx!

P.D.: sorry if my english is bad... jeje

User avatar
Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:

Post by Debashis Maitra » Wed Mar 07, 2007 7:14 pm

Post output part of your code
then anyone can help you

problem says output should be
I evol .uoy<== new line
uoY evol .em<== new line
er'eW a yppah .ylimaf<== new line
<==cursor is here but no new line
Best of luck
Akash chhoyar swopno
Dream to touch the sky

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Post by x140l31 » Tue May 15, 2007 1:53 pm

This is my code:

Code: Select all

#include <iostream>
#include <string>
#include <sstream>
using namespace std;  
int main() {	
    string line;	
    while (getline(cin, line)) {		
          for (int i = 0; i < (int)line.size(); ++i) {			
              if (line[i] == ' ') cout << " ";			
              else {				
                   string word;				
                   while (line[i] != ' ' and i < (int)line.size()) {					
                         word = line[i] + word;					
                         ++i;				
                   }				
                   cout << word; 				
                   if (line[i] == ' ') cout << " ";			
              }		
          }		
          cout << endl;	
    }
} 
:(

That's Good
New poster
Posts: 2
Joined: Sat May 19, 2007 11:53 pm

PE in prob 483

Post by That's Good » Sun May 27, 2007 11:29 pm

It's not difficult to get PE in this prob. It usually happens.

In your code you defined the space twice one in if and another in outside else within the same for loop. Here I think the matter U can get PE. U better check that again. I think that will help now. :wink:
Everything have a solution. Perhaps You don't know.

NaIx
New poster
Posts: 4
Joined: Sat Jun 02, 2007 5:49 pm
Location: indonesia

Post by NaIx » Wed Jun 06, 2007 3:30 am

somebody help plzz... i got WA... i don't know why i got WA.......

Code: Select all

#include<cstdio>
#include<cstring>
#include<cstdlib>
#define MAX 1000000

int main()
{
    char kata[MAX];
    long int start, end, len, i, j;
    while(gets(kata))
    {
        len=strlen(kata);
        start=end=0;
        for(i=0;i<len;i++)
        {
            if(kata[i]!=' '&& kata[i]!='.')
                end++;
            else if(kata[i]==' ')
            {
                for(j=end-1;j>=start;j--)
                {
                    printf("%c",kata[j]);
                //    system("pause");
                }    
                start=end;
                if(kata[start]==' ')
                {
                    printf(" ");
                //    system("pause");
                    start++;
                    end=start;   
                }
            }
            else if(kata[i]=='.')
            {
                for(j=end;j>=start;j--)
                {
                    printf("%c",kata[j]);
                //    system("pause");
                }    
                start=end;
           }
        }
        printf("\n");
    }
    return 0;
}

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Jun 06, 2007 11:45 am

Try the cases.

Input:

Code: Select all

This is the problem!!!
My email is a@aa@aaa.com@
Output:

Code: Select all

sihT si eht !!!melborp
yM liame si @moc.aaa@aa@a
Hope these help.
Ami ekhono shopno dekhi...
HomePage

Post Reply

Return to “Volume 4 (400-499)”