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

Anamika Paul
New poster
Posts: 1
Joined: Thu Jun 25, 2015 11:28 am

Re: 483 - Word Scramble

Post by Anamika Paul » Thu Jun 25, 2015 11:33 am

please help me , I am getting Runtime error. My code is given below.

Code: Select all

#include<stdio.h>
#include<string.h>
char str[90000];
int reverse(int i){
     int k,j,br;
     br=-1;
     for(k=0;k<=i;k++){
         if(str[k]==' ')
            { for(j=k-1;j>br;j--)
              { printf("%c",str[j]); }
            if(k!=i)printf(" ");            
                br=k;  }} 
            return 0;}
int main()
{    char c,i; 
    i=0;
while ((c = getchar())!=EOF) {
        if(c!='\n'){
         str[i]=c;
         i++; }
        else{
        str[i]=' ';
         reverse(i);
         i=0;
          printf("\n");
         } } return 0;
         }
Last edited by brianfry713 on Wed Aug 19, 2015 8:49 pm, edited 1 time in total.
Reason: Added code block

prokawsar
New poster
Posts: 7
Joined: Tue Aug 04, 2015 5:01 pm

TLE: 483 - Word Scramble

Post by prokawsar » Fri Aug 07, 2015 1:33 pm

Getting PE, plese help ! but my code works fine for uDebug.

Code: Select all

/* Date: 07.08.15
Problem: Word Scramble
*/

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

int main()
{
    int a=0,i,d,e, p=0;
	char c[1000], m[1000];
	char z = '\0';

	while(gets(c)){

		for(i=0; i<=strlen(c); i++){
			m[p] = c[i];
			a++;
			p++;
			if(c[i]== 32 || c[i]== z){
				for(e=p-2; e>=0; e--){
					printf("%c", m[e]);
				} printf(" ");
				p=0;
				a=0;
			}
		} printf("\n");
	}
    return 0;
}


Alexander_The_Great
New poster
Posts: 1
Joined: Sat Mar 05, 2016 1:45 pm

Re: 483 - Word Scramble

Post by Alexander_The_Great » Sat Mar 05, 2016 2:10 pm

Here is my code it gives runtime error by judge and I am unable to fix it. Can anyone suggest something It would be really Helpful ?.Thanks in advance. :D

Code: Select all

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    string s;
     string str[500000];
    long long int l=0;
    while(getline(cin,s))
    {    l=0;
         vector <string> s1;
        istringstream ise(s);
         for(string s; ise>>s;)
            s1.push_back(s);                                                               // spliting the string on whitespaces.
        for(vector<string>:: iterator i=s1.begin();i!=s1.end();i++)
        {
            str[l++]=*i;
        }
        for(int j=0;j<l;j++)
        {
            for(int k=str[j].length()-1;k>=0;k--)
            {
                cout<<str[j][k];
            }
           cout<<" ";
        }
        cout<<"\n";
    }
    return 0;

}

Post Reply

Return to “Volume 4 (400-499)”