Getting WA in 10815 - Andy's First Dictionary

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

Moderator: Board moderators

Getting WA in 10815 - Andy's First Dictionary

Postby Joarder » Mon Nov 28, 2011 11:53 pm

Why my code getting WA...??? :roll: :roll: :roll:
Plz.... Someone Cheak it...
or Give me some test cases...
here is my code....

/*
* File: 10815 - Andy's First Dictionary.cpp
* Tag: String
* http://uva.onlinejudge.org/external/108/10815.html


* Runtime:
* Author: Shoshi
* Created on November 28, 2011, 9:00 PM
*/

#pragma warning (disable : 4786)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long

using namespace std;

int main() {
//freopen("10815 - Andy's First Dictionary_in.txt", "r", stdin);
map<string,bool>m;
map<string,bool>::iterator it;
string str,str1;
int l,i;
while(cin>>str) {
l=str.length();
str1.clear();
for(i=0;i<l;i++) {
if((str[i]>='A' && str[i]<='Z') || (str[i]>='a' && str[i]<='z') || (str[i]>='0' && str[i]<='9')) {
str[i]=tolower(str[i]);
str1+=str[i];
}
else {
str.erase(i,1);
i--;
l--;
if(!str1.empty()) {
m[str1]=true;
str1.clear();
}
}
}
if(!str1.empty()) {
m[str1]=true;
str1.clear();
}
}
for(it=m.begin();it!=m.end();it++)
cout<<(*it).first<<endl;
return 0;
}
Joarder
New poster
 
Posts: 2
Joined: Mon Nov 28, 2011 11:26 pm

Re: Getting WA in 10815 - Andy's First Dictionary

Postby mgavin2 » Tue Jul 31, 2012 11:09 pm

Joarder wrote:
Code: Select all
int main() {
   //freopen("10815 - Andy's First Dictionary_in.txt", "r", stdin);
   map<string,bool>m;
   map<string,bool>::iterator it;
   string str,str1;
   int l,i;
   while(cin>>str) {
      l=str.length();
      str1.clear();
      for(i=0;i<l;i++) {
         if((str[i]>='A' && str[i]<='Z') || (str[i]>='a' && str[i]<='z') || (str[i]>='0' && str[i]<='9')) {
            str[i]=tolower(str[i]);
            str1+=str[i];
         }
         else {
            str.erase(i,1);
            i--;
            l--;
            if(!str1.empty()) {
               m[str1]=true;
               str1.clear();
            }
         }
      }
      if(!str1.empty()) {
         m[str1]=true;
         str1.clear();
      }
   }
   for(it=m.begin();it!=m.end();it++)
      cout<<(*it).first<<endl;
   return 0;
}


Ok, it seems like you try your best to pull out punctuation and sort that situation out. So with input like "help.me" you get help and me, but if you hit a word that's possessive, then you're screwed.

eg. It was the dog's job to bark at the mailman.

you would end up with the word "s" in your list... Perhaps you should try to filter out any one letter words that aren't A or I?

Also when you need a set of unique elements, just use the set datatype
eg.
Code: Select all
#include <set>
#include <string>
using std::set;
using std::string;
set<string> words;


try to find a resource to explain more about it :)
mgavin2
New poster
 
Posts: 21
Joined: Sat Jul 28, 2012 6:29 pm

Re: Getting WA in 10815 - Andy's First Dictionary

Postby mgavin2 » Tue Jul 31, 2012 11:53 pm

also perhaps contractions in words : http://en.wikipedia.org/wiki/Contraction_(grammar)
mgavin2
New poster
 
Posts: 21
Joined: Sat Jul 28, 2012 6:29 pm

Re: Getting WA in 10815 - Andy's First Dictionary

Postby mgavin2 » Wed Aug 01, 2012 12:42 am

Nevermind. I don't think it matters. I think your problem is accepting characters of '0'-'9' when it says in the problem statement "a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with only one letter are also to be considered." ...

after trying to solve it now I'm stuck in WA too. WAwsome.
mgavin2
New poster
 
Posts: 21
Joined: Sat Jul 28, 2012 6:29 pm

Re: Getting WA in 10815 - Andy's First Dictionary

Postby uvasarker » Sun Sep 02, 2012 1:18 pm

I am getting TLE help me.........please
Code: Select all
/* Removed */
Thanks guru (brianfry713).
I got AC
Last edited by uvasarker on Fri Sep 07, 2012 2:51 pm, edited 2 times in total.
uvasarker
Learning poster
 
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh

Re: Getting WA in 10815 - Andy's First Dictionary

Postby brianfry713 » Wed Sep 05, 2012 1:39 am

Try rewriting it without using strtok, just test each character to see if it's a-z or A-Z. Also try sorting directly instead of using a map. Your tolow function is also going to be slow.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Getting WA in 10815 - Andy's First Dictionary

Postby alimbubt » Mon Dec 17, 2012 6:05 am

Getting WA.....please help me....Is my input process is correct??

Code: Select all
Cut After Accepted
Last edited by alimbubt on Sun Mar 17, 2013 10:40 am, edited 1 time in total.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
alimbubt
New poster
 
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh

Re: Getting WA in 10815 - Andy's First Dictionary

Postby brianfry713 » Tue Dec 18, 2012 12:17 am

There may be more than 27 words. You may be modifying s[-1]. You could use a set instead of a map.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Getting WA in 10815 - Andy's First Dictionary

Postby alimbubt » Tue Dec 18, 2012 10:08 am

Code: Select all
Cut After Accepted
Last edited by alimbubt on Sun Mar 17, 2013 10:40 am, edited 1 time in total.
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/
alimbubt
New poster
 
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Location: BUBT,Dhaka, Bangladesh

Re: Getting WA in 10815 - Andy's First Dictionary

Postby brianfry713 » Wed Dec 19, 2012 12:46 am

input:
Code: Select all
don't
AC output:
Code: Select all
don
t
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume CVIII

Who is online

Users browsing this forum: No registered users and 1 guest