Page 3 of 3
WA--- 11062 - Andy's Second Dictionary
Posted: Sat Dec 10, 2011 9:54 am
by drubo
- Try to overcome jan's input >> u will get accepted
Jan vai thanks.........
Re: 11062 - Andy's Second Dictionary
Posted: Wed Jul 18, 2012 3:07 pm
by AhmadKhatar
Hi!
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;
}
Thanks in advance!

Re: 11062 - Andy's Second Dictionary
Posted: Thu Jul 19, 2012 2:56 am
by brianfry713
Don't print a blank line in the output.
Re: 11062 - Andy's Second Dictionary
Posted: Thu Jul 19, 2012 4:45 am
by AhmadKhatar
But the problem description says that each word should be displayed in a newline.

Re: 11062 - Andy's Second Dictionary
Posted: Thu Jul 19, 2012 11:34 pm
by brianfry713
Is a blank line a word?
Re: 11062 - Andy's Second Dictionary
Posted: Thu Jul 19, 2012 11:56 pm
by AhmadKhatar
Thanks! I got AC.
Re: 11062 - Andy's Second Dictionary
Posted: Sun Jun 16, 2013 2:22 pm
by choice
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;
}
Re: 11062 - Andy's Second Dictionary
Posted: Tue Jun 18, 2013 12:56 am
by brianfry713
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.
Re: 11062 - Andy's Second Dictionary
Posted: Wed Jun 19, 2013 3:30 am
by choice
thank u for your help, I got ac