Page 8 of 9

uva 483 Word Scramble

Posted: Sat Feb 08, 2014 4:15 am
by terry646623
Why am I get output limit? Please help :cry:

Code: Select all

Got accepted when using while( get(letter) ) {...}
Thank You! :D

Re: uva 483 Word Scramble

Posted: Tue Feb 11, 2014 12:19 am
by brianfry713
don't use system("pause");
EOF will never equal 1. You could instead do something like while(gets(letter)) {

UVA 483. Getting WA. Please Help.

Posted: Fri May 16, 2014 3:03 pm
by rajib2k10
It is printing a space before start of each output.

Code: Select all

#include <algorithm>
#include <bitset>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <stdio.h>
#include <sstream>
#include <utility>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define LL long long

using namespace std;

int main()
{
    string input;
    char names[100];
    while(getline(cin,input))
    {
        istringstream iss(input);
        while(iss>>names)
        {
            int len = strlen(names);
            for(int i=len;i>=0;i--)
            {
                if(names[i] == ' ')
                {
                    continue;
                }
                cout<<names[i];
            }
        }
        cout<<"\n";
    }
return 0;
}


Re: UVA 483. Getting WA. Please Help.

Posted: Fri May 16, 2014 9:50 pm
by brianfry713
You're printing a null char at the end of each line.

Re: UVA 483. Getting WA. Please Help.

Posted: Fri May 16, 2014 11:01 pm
by rajib2k10
Actually, I didn't get it. I didn't use a cout to print a null character. so please can you tell me where is the bug. if you can then please tell me what should i do to not print a null character so that i can learn that error. Thanks

Re: UVA 483. Getting WA. Please Help.

Posted: Tue May 20, 2014 2:52 am
by brianfry713
There is a null char at the end of each string. strlen returns the index to that null char and that is the first thing you're printing.

Getting WA with 483 Word Scramble

Posted: Mon Jun 16, 2014 2:31 pm
by Shadow_Coder
Hello. I'm trying to solve the 483 Word Scramble problem, but I'm getting WA. When I run the code on my computer with the given test data, the result comes alright. But, it still gets a WA. Below given is my code. Can anybody help me?

Code: Select all

#include <sstream>
#include <string>
#include <iostream>
using namespace std;

string strrev(string s){
    string t(s.rbegin(), s.rend());
    return t;
}

int main() {
	string s, t;
	while(!cin.eof()){
		getline(cin, s);
		istringstream buffer(s);
		while(buffer >> t){
			cout << strrev(t) << " ";
		}
		cout << "\n";
	}
	return 0;
}

Re: Getting WA with 483 Word Scramble

Posted: Mon Jun 16, 2014 8:44 pm
by brianfry713
Don't print a space at the end of a line.

Re: Getting WA with 483 Word Scramble

Posted: Tue Jun 17, 2014 9:33 am
by Shadow_Coder
Thanks, got AC! I had to prevent the newline and the space at the end of the last line. Below is the code.

Code: Select all

#include <sstream>
#include <string>
#include <iostream>
using namespace std;

string strrev(string s){
    string t(s.rbegin(), s.rend());
    return t;
}

int main() {
   string s, t;
   while(!cin.eof()){
      getline(cin, s);
      istringstream buffer(s);
      while(buffer >> t){
         cout << strrev(t);
         if(!buffer.eof()) { cout << " "; }
      }
      if(!cin.eof()) cout << "\n";
   }
   return 0;
}

Re: Getting WA with 483 Word Scramble

Posted: Sun Aug 17, 2014 8:25 pm
by shaficse
I am getting presentation error .
Please someone help me?

#include <iostream>
#include <cstdio>
#include <cstring>


using namespace std;
void reverse_string(char* pch)
{
int len=strlen(pch);
char temp;
for(int i=0;i<len/2;i++)
{
temp=pch;
pch=pch[len-i-1];
pch[len-i-1]=temp;
}
printf("%s ",pch);
}


int main()
{

char str[10000];
while(gets(str))
{
char *pch;
pch=strtok(str," ");
while(pch!=NULL)
{
reverse_string(pch);
pch=strtok(NULL," ");
}
printf("\n");
}

return 0;
}

Re: Getting WA with 483 Word Scramble

Posted: Mon Aug 18, 2014 1:25 am
by lighted
You are printing extra space at the end of line. You can make following changes

Code: Select all

printf("%s ",pch);
It must be

Code: Select all

printf("%s",pch);
Add one line

Code: Select all

while(pch!=NULL)
{
    reverse_string(pch);
    pch=strtok(NULL," ");
    if (pch != NULL) putchar(' ');
}
Don't forget to remove your code after getting accepted. 8)

By the way,

Code: Select all

use code tags

Re: 483 - Word Scramble

Posted: Sun Aug 24, 2014 10:52 pm
by shaficse
thank you lighted . i can not do this type of error again.

Re: 483 - Word Scramble Runtime Error

Posted: Sat Dec 06, 2014 6:28 pm
by moxlotus
The following code executes perfectly fine on my machine but gets RE on UVa.

Code: Select all

 AC
Can someone tell me where the source of RE is in this piece of code? perhaps a test case that can cause RE will be much appreciated. :)

Re: 483 - Word Scramble

Posted: Sun Dec 07, 2014 3:39 pm
by lighted
Increase value of size by 1 for '\0' character.

Re: 483 - Word Scramble

Posted: Mon Dec 08, 2014 10:34 am
by moxlotus
lighted wrote:Increase value of size by 1 for '\0' character.
Thanks.