11062 - Andy's Second Dictionary

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

drubo
New poster
Posts: 4
Joined: Thu Jul 21, 2011 12:26 pm

WA--- 11062 - Andy's Second Dictionary

Post by drubo » Sat Dec 10, 2011 9:54 am

  • Try to overcome jan's input >> u will get accepted
    Jan vai thanks.........

AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: 11062 - Andy's Second Dictionary

Post by AhmadKhatar » Wed Jul 18, 2012 3:07 pm

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! :D

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11062 - Andy's Second Dictionary

Post by brianfry713 » Thu Jul 19, 2012 2:56 am

Don't print a blank line in the output.
Check input and AC output for thousands of problems on uDebug!

AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: 11062 - Andy's Second Dictionary

Post by AhmadKhatar » Thu Jul 19, 2012 4:45 am

But the problem description says that each word should be displayed in a newline. :-?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11062 - Andy's Second Dictionary

Post by brianfry713 » Thu Jul 19, 2012 11:34 pm

Is a blank line a word?
Check input and AC output for thousands of problems on uDebug!

AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: 11062 - Andy's Second Dictionary

Post by AhmadKhatar » Thu Jul 19, 2012 11:56 pm

Thanks! I got AC.

choice
New poster
Posts: 2
Joined: Sun Jun 16, 2013 2:06 pm

Re: 11062 - Andy's Second Dictionary

Post by choice » Sun Jun 16, 2013 2:22 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11062 - Andy's Second Dictionary

Post by brianfry713 » Tue Jun 18, 2013 12:56 am

Your code doesn't match the sample I/O. The sample input has:

Code: Select all

Dis-
ney-
land
This should be counted as disneyland.

Code: Select all

Disney-land
This should be counted as disney-land.

Code: Select all

Dis-
neyland
This should be counted as disneyland.
Check input and AC output for thousands of problems on uDebug!

choice
New poster
Posts: 2
Joined: Sun Jun 16, 2013 2:06 pm

Re: 11062 - Andy's Second Dictionary

Post by choice » Wed Jun 19, 2013 3:30 am

thank u for your help, I got ac

Post Reply

Return to “Volume 110 (11000-11099)”