483 - Word Scramble
Moderator: Board moderators
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
483 WHY WA???
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;
}
-
- New poster
- Posts: 19
- Joined: Mon May 29, 2006 4:12 pm
483 PE Help PLZ
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;
}
-
- New poster
- Posts: 13
- Joined: Wed Sep 08, 2004 10:54 am
I have two questions to this problem:
1.) What if there is one or more blank lines in the input?
2.) what if there are more than one white space characters between words in a line?
THX in advance!
1.) What if there is one or more blank lines in the input?
Code: Select all
bla blob blub
123... 0.98
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.
483 why WA , plz help me !!
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;
}
483. W.A, Who can advice me?
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. : )
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;
}