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

sds1100
Learning poster
Posts: 95
Joined: Sat Dec 10, 2005 2:09 pm

Post by sds1100 »

i don't know

Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

483 PE

Post by Artikali »

483 PE
i deleted all white spaces.
what i should do more to get AC.

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

you cant delete all white space,
when some white spaces are needed for the output to get accepted
you should remove unnecessary white spaces and
unnecessery blank lines.. ok?

d31mOZ
New poster
Posts: 7
Joined: Sat Apr 01, 2006 8:00 pm

Post by d31mOZ »

The last output don't should be:

for ---> as..
this --->..sa

???????

d31mOZ
New poster
Posts: 7
Joined: Sat Apr 01, 2006 8:00 pm

483 WHY WA???

Post by d31mOZ »

I submit this code and i get WA, WHY??? It's a problem so easy!!!!!!

Code: Select all

#include <stdio.h>

//483

int main()
{
        char c, s[100]; int cant = 0;
        while ((c = getchar()) != EOF)
        {
                if (c != '\n')
                {
                        if (c != ' ')
                        {
                                s[cant++] = c;
                        } else
                        {
                                for (int i = cant - 1; i > -1; i--)
                                        printf("%c", s[i]);
                                cant = 0;
                                printf(" ");
                        }
                }
                else
                {
                        for (int i = cant - 1; i > -1; i--)
                                printf("%c", s[i]);
                        printf("\n");
                        cant = 0;
                }
        }
        return 0;
}

Dave
New poster
Posts: 5
Joined: Sat May 06, 2006 9:57 am
Location: England, My Chair

Post by Dave »

Have you tested it with different inputs and outputs before submitting.

Try putting the sample input in a file in the same directory as the executable. Then run

'YOUR PROGRAM NAME' < 'INPUT FILE' > 'OUTPUT FILE'

and see if you get the same as the sample output.

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci »

Try to increase your array size, I used 10000000 chars but I guess 1000000 will do..., good luck,

Yandry.

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci »

d31mOZ wrote:The last output don't should be:

for ---> as..
this --->..sa

???????
Yes you are right acorrding to my AC program :D

d31mOZ
New poster
Posts: 7
Joined: Sat Apr 01, 2006 8:00 pm

Post by d31mOZ »


thomas1016
New poster
Posts: 19
Joined: Mon May 29, 2006 4:12 pm

483 PE Help PLZ

Post by thomas1016 »

Can you guys tall me why it is PE???

Code: Select all

#include <iostream>
#include <string> 
using namespace std;
int main(void){
    int i,u,j;
    string a;
    while(getline(cin,a)){
                          if(a==""){continue;}
                          i=0;                
                          //cout<<a.length()<<endl;
                          while(i<a.length()){
                          
                        //  cout<<a.length()<<endl;1
                          for(u=i;a[u]!=' ' && u<=a.length();u++);
                          //cout<<a<<endl;
                          //system("pause");
                        //  cout<<i;
                        j=u-1;
                        if(j==a.length()){
                                         j--;
                                         }
                          for(;j>=i;j--){
                                              cout<<a[j];
                                              }
                         
                          if(u-1!=a.length()){
                                            cout<<a[u];
                                            
                                            }
                          i=u+1;
                          }
                          cout<<endl;
                          }




    //system("pause");
    return 0;
    }




BenderBendingRodriguez
New poster
Posts: 13
Joined: Wed Sep 08, 2004 10:54 am

Post by BenderBendingRodriguez »

I have two questions to this problem:

1.) What if there is one or more blank lines in the input?

Code: Select all

bla blob blub


123... 0.98
2.) what if there are more than one white space characters between words in a line?

Code: Select all

bla                                   blob                                  blub                              

THX in advance! :)
When you do things right, people won't be sure you've done anything at all.

alfreadx
New poster
Posts: 4
Joined: Fri Aug 04, 2006 11:06 am
Location: Taiwan

483 why WA , plz help me !!

Post by alfreadx »

Code: Select all

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

int main()
{
        int i,len;
        string str;
        stack<char> x;

        while(getline(cin,str)){
                if(cin.eof())   break;

                for(i=0; i <= str.length(); ++i){
                        if(str[i] == ' ' || str[i] == '\0'){
                                while(!x.empty()){
                                        cout << x.top() ;
                                        x.pop();
                                }
                                if(str[i] != '\0')      cout << " ";
                                else    cout << endl;
                        }
                        else    x.push(str[i]);
                }

        }
		
        return 0;
}

why wa ?? i can't find bug. thanks.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

When they say "whitespace" instead of "space" that means that they will use any whitespace (I check for '\t' and '\b' on top of those that you check).

alfreadx
New poster
Posts: 4
Joined: Fri Aug 04, 2006 11:06 am
Location: Taiwan

thx

Post by alfreadx »

thank you.
i got AC bot PE.
that's ok.

mosaick2
New poster
Posts: 21
Joined: Wed Mar 08, 2006 4:05 am

483. W.A, Who can advice me?

Post by mosaick2 »

I have tested all sample that I could find below articles.
And I have passed the testcases.
BUT, online-judge give me W.A(Wrong Answer)
Frankly, I believe online-judge. So I think I have a fault in my program.
Who can give advice me aboue this?
Thankx, your help. : )

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;
	while (getline(cin, str)) {
		for (int i  = 0; i <= str.length(); i++) {
			if (str[i] != ' ' && str[i] != '\t' && str[i] != '\0') {
				stk.push(str[i]);
			}
			else {
				while (!stk.empty()) {
					cout << stk.top(); 
					stk.pop();
				}
				if (str[i] == ' ')
					cout << ' ';
				else if (str[i] == '\t')
					cout << '\t';
				else if (str[i] == '\0')
					cout << endl;
			}
		}
	}
	return 0;
}

Post Reply

Return to “Volume 4 (400-499)”