- Try to overcome jan's input >> u will get accepted
Jan vai thanks.........
11062 - Andy's Second Dictionary
Moderator: Board moderators
WA--- 11062 - Andy's Second Dictionary
-
- New poster
- Posts: 28
- Joined: Fri Mar 30, 2012 12:57 am
Re: 11062 - Andy's Second Dictionary
Hi!
Does anybody know where my mistake is?
Thanks in advance! ![:D](./images/smilies/icon_biggrin.gif)
Does anybody know where my mistake is?
Code: Select all
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <algorithm>
using std::sort;
#include <set>
using std::set;
#include <cctype>
using std::tolower;
using std::isalpha;
#include <cstring>
using std::strlen;
set<string> s;
int main()
{
string tStr;
char tLine [ 10000 ];
bool cont = false;
tStr = "";
while ( cin.getline( tLine, 10000, '\n' ) )
{
cont = false;
for ( int i = 0; i < strlen( tLine ); i++ )
{
if ( isalpha( tLine[ i ] ) )
{
tStr += tolower( tLine[ i ] );
}
else if ( tLine[ i ] == '-' )
{
if ( i != strlen( tLine ) - 1 )
{
tStr += tLine[ i ];
}
else
{
cont = true;
}
}
else
{
if ( tStr.length() > 0 )
{
s.insert( tStr );
tStr = "";
}
}
}
if ( cont == false )
{
s.insert( tStr );
tStr = "";
}
else // remainder on the next line
{
// do nothing
}
}
if ( cont == true )
{
s.insert( tStr );
}
string dic [ 500 ];
int cnt = 0;
set<string>::iterator begIter = s.begin();
set<string>::iterator endIter = s.end();
for ( ; begIter != endIter; begIter++ )
{
dic[ cnt++ ] = *begIter;
}
sort( &dic[ 0 ], &dic[ cnt ] );
for ( int i = 0; i < cnt; i++ )
{
cout << dic[ i ] << endl;
}
return 0;
}
![:D](./images/smilies/icon_biggrin.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11062 - Andy's Second Dictionary
Don't print a blank line in the output.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 28
- Joined: Fri Mar 30, 2012 12:57 am
Re: 11062 - Andy's Second Dictionary
But the problem description says that each word should be displayed in a newline. ![:-?](./images/smilies/icon_confused.gif)
![:-?](./images/smilies/icon_confused.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11062 - Andy's Second Dictionary
Is a blank line a word?
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 28
- Joined: Fri Mar 30, 2012 12:57 am
Re: 11062 - Andy's Second Dictionary
Thanks! I got AC.
Re: 11062 - Andy's Second Dictionary
here is my code, i can not understand the line "The hyphen character is part of the word if, and only if, not followed by a newline. ", suppose the input is
"Dis-
ney-
land"
why it is Disney-land, not Disneyland
so, for this, i cannot use any condition for this line and cannot complete my code, plz help...
#include<algorithm>
#include<iostream>
#include<iterator>
#include<cassert>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<complex>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
int main()
{
int l;
set<string>st;
string s;
set<string>::iterator it;
int f=0;
string p;
string x;
while(getline(cin,s))
{
if(f==0){
p="";
x="";
}
else{
p+=x;
x="";
}
l=s.size();
for(int i=0;i<=l;i++)
{
if(i==l&&s[l-1]=='-')
{
f=1;
x+=p;
p="";
}
else if(isalpha(s))
{
p+=tolower(s);
}
else if(s=='-')
{
continue;
}
else if(p!="") {
st.insert(p);
p="";
}
}
}
it=st.begin();
for(it;it!=st.end();it++)
{
cout<<*it<<endl;
}
return 0;
}
"Dis-
ney-
land"
why it is Disney-land, not Disneyland
so, for this, i cannot use any condition for this line and cannot complete my code, plz help...
#include<algorithm>
#include<iostream>
#include<iterator>
#include<cassert>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<complex>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<deque>
#include<list>
#include<set>
#include<map>
using namespace std;
int main()
{
int l;
set<string>st;
string s;
set<string>::iterator it;
int f=0;
string p;
string x;
while(getline(cin,s))
{
if(f==0){
p="";
x="";
}
else{
p+=x;
x="";
}
l=s.size();
for(int i=0;i<=l;i++)
{
if(i==l&&s[l-1]=='-')
{
f=1;
x+=p;
p="";
}
else if(isalpha(s))
{
p+=tolower(s);
}
else if(s=='-')
{
continue;
}
else if(p!="") {
st.insert(p);
p="";
}
}
}
it=st.begin();
for(it;it!=st.end();it++)
{
cout<<*it<<endl;
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11062 - Andy's Second Dictionary
Your code doesn't match the sample I/O. The sample input has:
This should be counted as disneyland.
This should be counted as disney-land.
This should be counted as disneyland.
Code: Select all
Dis-
ney-
land
Code: Select all
Disney-land
Code: Select all
Dis-
neyland
Check input and AC output for thousands of problems on uDebug!
Re: 11062 - Andy's Second Dictionary
thank u for your help, I got ac