123 - Searching Quickly

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

Moderator: Board moderators

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

[Resolved] 123 Searching Quickly - WA

Post by bugzpodder »

hmm 123 seems easy enough w/ no tricks. but i got WA. pretty surprised. anyone care to take a look? thx

[cpp]//123 Searching Quickly

#include<vector>
#include<string>
#include<algorithm>

using namespace std;

struct Keyword {
string st;
int ind,spos,epos; //ind - the index in the original order
//spos,epos starting pos,ending pos of keyword
};
bool operator<(const Keyword p, const Keyword q){
return p.st<q.st || (p.st==q.st && p.ind<q.ind) ||
(p.st==q.st && p.ind==q.ind && p.spos<q.spos);
}


int main(){
vector<string> ignore;
vector<Keyword> keywords;
string word;
while(true) { //get all the ignore words
cin>>word;
if (word=="::") break;
ignore.push_back(word);
}
char sent[10005];
string line[200];
int cnt=0,i,j,k;

while(true){
while(cin.peek()==' ' || cin.peek()=='\n') cin.ignore();
if (cin.eof()) break;
cin.getline(sent,10005);
string str(sent);
for (i=0;i<str.length();i++) //change to lower case
line[cnt]+=tolower(sent);

for (i=0;i<str.length();){
string st;
for (j=i;str[j]!=' ' && j<str.length();j++); //find the next space
if (j-i>0){ //if not consecutive space
string t=line[cnt].substr(i,j-i);
for (k=0;k<ignore.size();k++) //check if it is ignored
if (t==ignore[k]) break;
if (k==ignore.size()){ //if not, add it to keyword
Keyword key;
key.st=t;
key.ind=cnt;
key.spos=i;
key.epos=j;
keywords.push_back(key);
}
}
i=j+1;
}

cnt++;
}

sort(keywords.begin(),keywords.end()); //sort the keywords
for (i=0;i<keywords.size();i++){ //output
cout<<line[keywords.ind].substr(0,keywords.spos);
for (j=0;j<keywords.st.length();j++)
cout<<toupper(keywords.st[j]);
cout<<line[keywords.ind].substr(keywords.epos)<<endl;
}

return 0;
}


[/cpp]
Last edited by bugzpodder on Tue Aug 05, 2003 7:10 pm, edited 2 times in total.

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

HINT:
The toupper class is defined as follows in ctype.h:
int toupper(int c);

HINT 2 (your output):
a portrait of the 658284738384 as a young man
the 658367697884 of man
a man is a man but 66856666766983798284 is a dog

Hope that helps!

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder »

wahh! It gave me the correct output (using toupper) with my compiler (gpp)!! well, thanks for your advice (finally I got accepted), yay! really appreciate your hints!

what compiler did you use?

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

$ gcc-2 -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/specs
gcc version 2.95.3-10 (cygwin special)

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

123 why WA?

Post by boatfish »

Here is my source code, I can't figure out why it keeps on WA.
[cpp]#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

struct srt{
string key;
int start;
string title;
};

srt table[3001];
set<string> ignore;

bool new_less(srt a,srt b){
return a.key<b.key;
}

int main(){
string t,result;
char bu;
int i,low,case_no,upper,j;
while(cin>>t)
if(t!="::")
ignore.insert(t);
else
break;

cin.get(bu);
case_no=0;
low=0;
upper=0;
while(cin.peek()!=EOF){
low=upper;
result="";
while(cin.peek()!='\n'){
cin>>t;
for(j=0;j<t.length();j++)
t[j]=tolower(t[j]);
if(ignore.find(t)==ignore.end()){
(table[upper]).key=t;
(table[upper]).start=result.length();
upper++;
case_no++;
}
result=result+t+' ';
}
result=result.substr(0,result.length()-1);
cin.get(bu);
for(i=low;i<upper;i++){
(table).title=result;
for(j=(table.start);j<(table.start)+((table).key).length();j++)
((table).title)[j]=toupper(((table.title))[j]);
}
}
sort(table,table+case_no,new_less);
for(i=0;i<case_no;i++)
cout<<(table).title<<endl;
return 0;
}[/cpp]

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Post by stcheung »

Mine is also W.A. for no obvious reason...any help? Thanks in advance.

[cpp]/* 123 */
#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <algorithm>

string ignore[50];
string titles[200];
string keywordStr[3000];
int keywordLine[3000];
int keywordPos[3000];
int ordering[3000];

struct compare
{
bool operator()(int index1, int index2)
{
if(keywordStr[index1] < keywordStr[index2])
return true;
else if(keywordStr[index1] == keywordStr[index2] &&
keywordLine[index1] < keywordLine[index2])
return true;
else return (keywordLine[index1] == keywordLine[index2] &&
keywordPos[index1] <= keywordPos[index2]);
}
};

int main()
{
string input;
int i=0;
while(true)
{
cin >> input;
if(input == "::")
break;
ignore = input;
i++;
}

sort(ignore, ignore + i);

getline(cin, input);
int j=0;
int index=0;
while(true)
{
getline(cin, input);
if(cin.eof())
break;

int len = input.length();
string word="";
int counter=0;
input+=" ";
string lowerTitle="";
for(int k=0; k<len+1; k++)
{
if(k < len)
lowerTitle+=tolower(input[k]);
if(input[k] == ' ' && word != "")
{
if(!binary_search(ignore, ignore+i, word) )
{
keywordStr[index] = word;
keywordLine[index] = j;
keywordPos[index] = counter;
ordering[index] = index;
index++;
}
word = "";
counter++;
}
else if(input[k] != ' ')
word+=tolower(input[k]);
}
titles[j] = lowerTitle;
j++;
}

sort(ordering, ordering+index, compare());
int tmp;
string title;
int pos;
for(int z=0; z<index; z++)
{
tmp = ordering[z];
title = titles[keywordLine[tmp]];
pos = keywordPos[tmp];
int len = title.length();
int counter=0;
char lastChar='\0';
string result="";
for(int x=0; x<len; x++)
{
if(title[x] != ' ' && lastChar == ' ')
counter++;

if(counter != pos)
result+=title[x];
else
result+=toupper(title[x]);
lastChar = title[x];
}

cout << result << "\n";
}


return 0;
}[/cpp]

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

boatfish,

your problem exists for this input:

Code: Select all

the
and
as
for
this
that
with
of
is
a
i
an
at
at
an
it
on
of
in
to
::
Fire in the Streets
Chaos
A troubled Feast
Amerika
A World of Ideas
Out of Africa
Death of a Salesman
Farewell Anatolia
Paradise Lost
Paradise Regained
The Descent of Man
The Ascent of Man
The Scent of a Woman
Yes I Can
Airport
Hotel
Roots
Woman On The Edge of Time
The Bean Trees
Song of Solomon
The Phantom Tollbooth
I Know Why the Caged Bird Sings
Animal Dreams
The Old Man and The Sea
Saint Maybe
The Sum of All Fears
Red Storm Rising
Another Fine Myth
Penguin Dreams and Stranger Things
To Kill a Mockingbird
The Adventures of Huckleberry Finn
Heart of Darkness
Anne of Green Gables
The Lion the Witch and the Wardrobe
Pride and Prejudice
The Bell Jar
Happy Are the Peacemakers
The Sun Also Rises
Portrait of The Artist As a Young Man
Sons and Lovers
A Dolls House
The Scarlet Letter
Second Foundation
Lucky Star And the Oceans of Venus
The Gods Themselves
Robot Visions
Foundations Edge
Foundation
Nightfall and Other Stories
Very Far Away From Anywhere Else
Time Enough For Love
Beyond This Horizon
Double Star
The Moon is a Harsh Mistress
Time for the Stars
The Unpleasant Profession of Jonathan Hoag
The Day After Tomorrow
Citizen of the Galaxy
Glory Road
I Will Fear No Evil
Space Cadet
The Cat Who Walks Through Walls
Neuromancer
Burning Chrome
Count Zero
Islands in the Net
Stranger in a Strange Land
The Collapsing Universe
I Sing the Body Electric
Timeless Stories for Today and Tomorrow
As On a Darkling Plain
Still Life With Woodpecker
The Color Purple
Curoious George
The Catcher in the Rye
The Wizard of Oz
A Connecticut Yankee in King Arthurs Court
One Fish Two Fish Red Fish Blue Fish
Eaters of the Dead
Communist Manifesto
Hop On Pop
Surprised by Joy
Lost in the Cosmos
The Universe Next Door
The Hiding Place
A Prayer for Owen Meany
A Tale of Two Cities
Interview with a Vampire
The World According to Garp
On Her Majestys Secret Service
Slaughterhouse Five
The Firm
Go Tell it on the Mountain
A Man is a Man but Bubblesort IS A DOG
The Quality School
The Satanic Verses
The Bone People
The Snow Leopard
Your output:

Code: Select all

the world ACCORDING to garp
the ADVENTURES of huckleberry finn
out of AFRICA
the day AFTER tomorrow
AIRPORT
the sum of ALL fears
the sun ALSO rises
AMERIKA
farewell ANATOLIA
ANIMAL dreams
ANNE of green gables
ANOTHER fine myth
very far away from ANYWHERE else
happy ARE the peacemakers
a connecticut yankee in king ARTHURS court
portrait of the ARTIST as a young man
the ASCENT of man
very far AWAY from anywhere else
the BEAN trees
the BELL jar
BEYOND this horizon
i know why the caged BIRD sings
one fish two fish red fish BLUE fish
i sing the BODY electric
the BONE people
a man is a man but BUBBLESORT is a dog
BURNING chrome
a man is a man BUT bubblesort is a dog
surprised BY joy
space CADET
i know why the CAGED bird sings
yes i CAN
the CAT who walks through walls
the CATCHER in the rye
CHAOS
burning CHROME
a tale of two CITIES
CITIZEN of the galaxy
the COLLAPSING universe
the COLOR purple
COMMUNIST manifesto
a CONNECTICUT yankee in king arthurs court
lost in the COSMOS
COUNT zero
a connecticut yankee in king arthurs COURT
CUROIOUS george
as on a DARKLING plain
heart of DARKNESS
the DAY after tomorrow
eaters of the DEAD
DEATH of a salesman
the DESCENT of man
a man is a man but bubblesort is a DOG
a DOLLS house
the universe next DOOR
DOUBLE star
animal DREAMS
penguin DREAMS and stranger things
EATERS of the dead
woman on the EDGE of time
foundations EDGE
i sing the body ELECTRIC
very far away from anywhere ELSE
time ENOUGH for love
i will fear no EVIL
very FAR away from anywhere else
FAREWELL anatolia
i will FEAR no evil
the sum of all FEARS
a troubled FEAST
another FINE myth
the adventures of huckleberry FINN
FIRE in the streets
the FIRM
one FISH two fish red fish blue fish
one fish two FISH red fish blue fish
one fish two fish red FISH blue fish
one fish two fish red fish blue FISH
slaughterhouse FIVE
FOUNDATION
second FOUNDATION
FOUNDATIONS edge
very far away FROM anywhere else
anne of green GABLES
citizen of the GALAXY
the world according to GARP
curoious GEORGE
GLORY road
GO tell it on the mountain
the GODS themselves
anne of GREEN gables
HAPPY are the peacemakers
the moon is a HARSH mistress
HEART of darkness
on HER majestys secret service
the HIDING place
the unpleasant profession of jonathan HOAG
HOP on pop
beyond this HORIZON
HOTEL
a dolls HOUSE
the adventures of HUCKLEBERRY finn
a world of IDEAS
INTERVIEW with a vampire
ISLANDS in the net
the bell JAR
the unpleasant profession of JONATHAN hoag
surprised by JOY
to KILL a mockingbird
a connecticut yankee in KING arthurs court
i KNOW why the caged bird sings
stranger in a strange LAND
the snow LEOPARD
the scarlet LETTER
still LIFE with woodpecker
the LION the witch and the wardrobe
LOST in the cosmos
paradise LOST
time enough for LOVE
sons and LOVERS
LUCKY star and the oceans of venus
on her MAJESTYS secret service
the old MAN and the sea
the descent of MAN
the ascent of MAN
portrait of the artist as a young MAN
a man is a MAN but bubblesort is a dog
a MAN is a man but bubblesort is a dog
communist MANIFESTO
saint MAYBE
a prayer for owen MEANY
the moon is a harsh MISTRESS
to kill a MOCKINGBIRD
the MOON is a harsh mistress
go tell it on the MOUNTAIN
another fine MYTH
islands in the NET
NEUROMANCER
the universe NEXT door
NIGHTFALL and other stories
i will fear NO evil
lucky star and the OCEANS of venus
the OLD man and the sea
ONE fish two fish red fish blue fish
nightfall and OTHER stories
OUT of africa
a prayer for OWEN meany
the wizard of OZ
PARADISE regained
PARADISE lost
happy are the PEACEMAKERS
PENGUIN dreams and stranger things
the bone PEOPLE
the PHANTOM tollbooth
the hiding PLACE
as on a darkling PLAIN
hop on POP
PORTRAIT of the artist as a young man
a PRAYER for owen meany
pride and PREJUDICE
PRIDE and prejudice
the unpleasant PROFESSION of jonathan hoag
the color PURPLE
the QUALITY school
one fish two fish RED fish blue fish
RED storm rising
paradise REGAINED
the sun also RISES
red storm RISING
glory ROAD
ROBOT visions
ROOTS
the catcher in the RYE
SAINT maybe
death of a SALESMAN
the SATANIC verses
the SCARLET letter
the SCENT of a woman
the quality SCHOOL
the old man and the SEA
SECOND foundation
on her majestys SECRET service
on her majestys secret SERVICE
i SING the body electric
i know why the caged bird SINGS
SLAUGHTERHOUSE five
the SNOW leopard
song of SOLOMON
SONG of solomon
SONS and lovers
SPACE cadet
lucky STAR and the oceans of venus
double STAR
time for the STARS
STILL life with woodpecker
timeless STORIES for today and tomorrow
nightfall and other STORIES
red STORM rising
stranger in a STRANGE land
penguin dreams and STRANGER things
STRANGER in a strange land
fire in the STREETS
the SUM of all fears
the SUN also rises
SURPRISED by joy
a TALE of two cities
go TELL it on the mountain
the gods THEMSELVES
penguin dreams and stranger THINGS
the cat who walks THROUGH walls
TIME enough for love
woman on the edge of TIME
TIME for the stars
TIMELESS stories for today and tomorrow
timeless stories for TODAY and tomorrow
the phantom TOLLBOOTH
the day after TOMORROW
timeless stories for today and TOMORROW
the bean TREES
a TROUBLED feast
one fish TWO fish red fish blue fish
a tale of TWO cities
the collapsing UNIVERSE
the UNIVERSE next door
the UNPLEASANT profession of jonathan hoag
interview with a VAMPIRE
lucky star and the oceans of VENUS
the satanic VERSES
VERY far away from anywhere else
robot VISIONS
the cat who WALKS through walls
the cat who walks through WALLS
the lion the witch and the WARDROBE
the cat WHO walks through walls
i know WHY the caged bird sings
i WILL fear no evil
the lion the WITCH and the wardrobe
the WIZARD of oz
the scent of a WOMAN
WOMAN on the edge of time
still life with WOODPECKER
a WORLD of ideas
the WORLD according to garp
a connecticut YANKEE in king arthurs court
YES i can
portrait of the artist as a YOUNG man
count ZERO
correct output:

Code: Select all

the world ACCORDING to garp
the ADVENTURES of huckleberry finn
out of AFRICA
the day AFTER tomorrow
AIRPORT
the sum of ALL fears
the sun ALSO rises
AMERIKA
farewell ANATOLIA
ANIMAL dreams
ANNE of green gables
ANOTHER fine myth
very far away from ANYWHERE else
happy ARE the peacemakers
a connecticut yankee in king ARTHURS court
portrait of the ARTIST as a young man
the ASCENT of man
very far AWAY from anywhere else
the BEAN trees
the BELL jar
BEYOND this horizon
i know why the caged BIRD sings
one fish two fish red fish BLUE fish
i sing the BODY electric
the BONE people
a man is a man but BUBBLESORT is a dog
BURNING chrome
a man is a man BUT bubblesort is a dog
surprised BY joy
space CADET
i know why the CAGED bird sings
yes i CAN
the CAT who walks through walls
the CATCHER in the rye
CHAOS
burning CHROME
a tale of two CITIES
CITIZEN of the galaxy
the COLLAPSING universe
the COLOR purple
COMMUNIST manifesto
a CONNECTICUT yankee in king arthurs court
lost in the COSMOS
COUNT zero
a connecticut yankee in king arthurs COURT
CUROIOUS george
as on a DARKLING plain
heart of DARKNESS
the DAY after tomorrow
eaters of the DEAD
DEATH of a salesman
the DESCENT of man
a man is a man but bubblesort is a DOG
a DOLLS house
the universe next DOOR
DOUBLE star
animal DREAMS
penguin DREAMS and stranger things
EATERS of the dead
woman on the EDGE of time
foundations EDGE
i sing the body ELECTRIC
very far away from anywhere ELSE
time ENOUGH for love
i will fear no EVIL
very FAR away from anywhere else
FAREWELL anatolia
i will FEAR no evil
the sum of all FEARS
a troubled FEAST
another FINE myth
the adventures of huckleberry FINN
FIRE in the streets
the FIRM
one FISH two fish red fish blue fish
one fish two FISH red fish blue fish
one fish two fish red FISH blue fish
one fish two fish red fish blue FISH
slaughterhouse FIVE
second FOUNDATION
FOUNDATION
FOUNDATIONS edge
very far away FROM anywhere else
anne of green GABLES
citizen of the GALAXY
the world according to GARP
curoious GEORGE
GLORY road
GO tell it on the mountain
the GODS themselves
anne of GREEN gables
HAPPY are the peacemakers
the moon is a HARSH mistress
HEART of darkness
on HER majestys secret service
the HIDING place
the unpleasant profession of jonathan HOAG
HOP on pop
beyond this HORIZON
HOTEL
a dolls HOUSE
the adventures of HUCKLEBERRY finn
a world of IDEAS
INTERVIEW with a vampire
ISLANDS in the net
the bell JAR
the unpleasant profession of JONATHAN hoag
surprised by JOY
to KILL a mockingbird
a connecticut yankee in KING arthurs court
i KNOW why the caged bird sings
stranger in a strange LAND
the snow LEOPARD
the scarlet LETTER
still LIFE with woodpecker
the LION the witch and the wardrobe
paradise LOST
LOST in the cosmos
time enough for LOVE
sons and LOVERS
LUCKY star and the oceans of venus
on her MAJESTYS secret service
the descent of MAN
the ascent of MAN
the old MAN and the sea
portrait of the artist as a young MAN
a MAN is a man but bubblesort is a dog
a man is a MAN but bubblesort is a dog
communist MANIFESTO
saint MAYBE
a prayer for owen MEANY
the moon is a harsh MISTRESS
to kill a MOCKINGBIRD
the MOON is a harsh mistress
go tell it on the MOUNTAIN
another fine MYTH
islands in the NET
NEUROMANCER
the universe NEXT door
NIGHTFALL and other stories
i will fear NO evil
lucky star and the OCEANS of venus
the OLD man and the sea
ONE fish two fish red fish blue fish
nightfall and OTHER stories
OUT of africa
a prayer for OWEN meany
the wizard of OZ
PARADISE lost
PARADISE regained
happy are the PEACEMAKERS
PENGUIN dreams and stranger things
the bone PEOPLE
the PHANTOM tollbooth
the hiding PLACE
as on a darkling PLAIN
hop on POP
PORTRAIT of the artist as a young man
a PRAYER for owen meany
pride and PREJUDICE
PRIDE and prejudice
the unpleasant PROFESSION of jonathan hoag
the color PURPLE
the QUALITY school
RED storm rising
one fish two fish RED fish blue fish
paradise REGAINED
the sun also RISES
red storm RISING
glory ROAD
ROBOT visions
ROOTS
the catcher in the RYE
SAINT maybe
death of a SALESMAN
the SATANIC verses
the SCARLET letter
the SCENT of a woman
the quality SCHOOL
the old man and the SEA
SECOND foundation
on her majestys SECRET service
on her majestys secret SERVICE
i SING the body electric
i know why the caged bird SINGS
SLAUGHTERHOUSE five
the SNOW leopard
song of SOLOMON
SONG of solomon
SONS and lovers
SPACE cadet
lucky STAR and the oceans of venus
double STAR
time for the STARS
STILL life with woodpecker
nightfall and other STORIES
timeless STORIES for today and tomorrow
red STORM rising
stranger in a STRANGE land
penguin dreams and STRANGER things
STRANGER in a strange land
fire in the STREETS
the SUM of all fears
the SUN also rises
SURPRISED by joy
a TALE of two cities
go TELL it on the mountain
the gods THEMSELVES
penguin dreams and stranger THINGS
the cat who walks THROUGH walls
woman on the edge of TIME
TIME enough for love
TIME for the stars
TIMELESS stories for today and tomorrow
timeless stories for TODAY and tomorrow
the phantom TOLLBOOTH
the day after TOMORROW
timeless stories for today and TOMORROW
the bean TREES
a TROUBLED feast
one fish TWO fish red fish blue fish
a tale of TWO cities
the collapsing UNIVERSE
the UNIVERSE next door
the UNPLEASANT profession of jonathan hoag
interview with a VAMPIRE
lucky star and the oceans of VENUS
the satanic VERSES
VERY far away from anywhere else
robot VISIONS
the cat who WALKS through walls
the cat who walks through WALLS
the lion the witch and the WARDROBE
the cat WHO walks through walls
i know WHY the caged bird sings
i WILL fear no evil
the lion the WITCH and the wardrobe
the WIZARD of oz
the scent of a WOMAN
WOMAN on the edge of time
still life with WOODPECKER
a WORLD of ideas
the WORLD according to garp
a connecticut YANKEE in king arthurs court
YES i can
portrait of the artist as a YOUNG man
count ZERO
Sorry about the size of this message...

Anyway, your problem starts on line #80 (FOUNDATION)
Last edited by xbeanx on Thu Oct 02, 2003 11:21 pm, edited 1 time in total.

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx »

stcheung:

Again sorry for the size of the message. Your problem starts on line #160 (PRIDE and prejudice)

Code: Select all

the world ACCORDING to garp
the ADVENTURES of huckleberry finn
out of AFRICA
the day AFTER tomorrow
AIRPORT
the sum of ALL fears
the sun ALSO rises
AMERIKA
farewell ANATOLIA
ANIMAL dreams
ANNE of green gables
ANOTHER fine myth
very far away from ANYWHERE else
happy ARE the peacemakers
a connecticut yankee in king ARTHURS court
portrait of the ARTIST as a young man
the ASCENT of man
very far AWAY from anywhere else
the BEAN trees
the BELL jar
BEYOND this horizon
i know why the caged BIRD sings
one fish two fish red fish BLUE fish
i sing the BODY electric
the BONE people
a man is a man but BUBBLESORT is a dog
BURNING chrome
a man is a man BUT bubblesort is a dog
surprised BY joy
space CADET
i know why the CAGED bird sings
yes i CAN
the CAT who walks through walls
the CATCHER in the rye
CHAOS
burning CHROME
a tale of two CITIES
CITIZEN of the galaxy
the COLLAPSING universe
the COLOR purple
COMMUNIST manifesto
a CONNECTICUT yankee in king arthurs court
lost in the COSMOS
COUNT zero
a connecticut yankee in king arthurs COURT
CUROIOUS george
as on a DARKLING plain
heart of DARKNESS
the DAY after tomorrow
eaters of the DEAD
DEATH of a salesman
the DESCENT of man
a man is a man but bubblesort is a DOG
a DOLLS house
the universe next DOOR
DOUBLE star
animal DREAMS
penguin DREAMS and stranger things
EATERS of the dead
woman on the EDGE of time
foundations EDGE
i sing the body ELECTRIC
very far away from anywhere ELSE
time ENOUGH for love
i will fear no EVIL
very FAR away from anywhere else
FAREWELL anatolia
i will FEAR no evil
the sum of all FEARS
a troubled FEAST
another FINE myth
the adventures of huckleberry FINN
FIRE in the streets
the FIRM
one FISH two fish red fish blue fish
one fish two FISH red fish blue fish
one fish two fish red FISH blue fish
one fish two fish red fish blue FISH
slaughterhouse FIVE
second FOUNDATION
FOUNDATION
FOUNDATIONS edge
very far away FROM anywhere else
anne of green GABLES
citizen of the GALAXY
the world according to GARP
curoious GEORGE
GLORY road
GO tell it on the mountain
the GODS themselves
anne of GREEN gables
HAPPY are the peacemakers
the moon is a HARSH mistress
HEART of darkness
on HER majestys secret service
the HIDING place
the unpleasant profession of jonathan HOAG
HOP on pop
beyond this HORIZON
HOTEL
a dolls HOUSE
the adventures of HUCKLEBERRY finn
a world of IDEAS
INTERVIEW with a vampire
ISLANDS in the net
the bell JAR
the unpleasant profession of JONATHAN hoag
surprised by JOY
to KILL a mockingbird
a connecticut yankee in KING arthurs court
i KNOW why the caged bird sings
stranger in a strange LAND
the snow LEOPARD
the scarlet LETTER
still LIFE with woodpecker
the LION the witch and the wardrobe
paradise LOST
LOST in the cosmos
time enough for LOVE
sons and LOVERS
LUCKY star and the oceans of venus
on her MAJESTYS secret service
the descent of MAN
the ascent of MAN
the old MAN and the sea
portrait of the artist as a young MAN
a MAN is a man but bubblesort is a dog
a man is a MAN but bubblesort is a dog
communist MANIFESTO
saint MAYBE
a prayer for owen MEANY
the moon is a harsh MISTRESS
to kill a MOCKINGBIRD
the MOON is a harsh mistress
go tell it on the MOUNTAIN
another fine MYTH
islands in the NET
NEUROMANCER
the universe NEXT door
NIGHTFALL and other stories
i will fear NO evil
lucky star and the OCEANS of venus
the OLD man and the sea
ONE fish two fish red fish blue fish
nightfall and OTHER stories
OUT of africa
a prayer for OWEN meany
the wizard of OZ
PARADISE lost
PARADISE regained
happy are the PEACEMAKERS
PENGUIN dreams and stranger things
the bone PEOPLE
the PHANTOM tollbooth
the hiding PLACE
as on a darkling PLAIN
hop on POP
PORTRAIT of the artist as a young man
a PRAYER for owen meany
PRIDE and prejudice
pride and PREJUDICE
the unpleasant PROFESSION of jonathan hoag
the color PURPLE
the QUALITY school
RED storm rising
one fish two fish RED fish blue fish
paradise REGAINED
the sun also RISES
red storm RISING
glory ROAD
ROBOT visions
ROOTS
the catcher in the RYE
SAINT maybe
death of a SALESMAN
the SATANIC verses
the SCARLET letter
the SCENT of a woman
the quality SCHOOL
the old man and the SEA
SECOND foundation
on her majestys SECRET service
on her majestys secret SERVICE
i SING the body electric
i know why the caged bird SINGS
SLAUGHTERHOUSE five
the SNOW leopard
song of SOLOMON
SONG of solomon
SONS and lovers
SPACE cadet
lucky STAR and the oceans of venus
double STAR
time for the STARS
STILL life with woodpecker
nightfall and other STORIES
timeless STORIES for today and tomorrow
red STORM rising
STRANGER in a strange land
stranger in a STRANGE land
penguin dreams and STRANGER things
fire in the STREETS
the SUM of all fears
the SUN also rises
SURPRISED by joy
a TALE of two cities
go TELL it on the mountain
the gods THEMSELVES
penguin dreams and stranger THINGS
the cat who walks THROUGH walls
woman on the edge of TIME
TIME enough for love
TIME for the stars
TIMELESS stories for today and tomorrow
timeless stories for TODAY and tomorrow
the phantom TOLLBOOTH
the day after TOMORROW
timeless stories for today and TOMORROW
the bean TREES
a TROUBLED feast
one fish TWO fish red fish blue fish
a tale of TWO cities
the collapsing UNIVERSE
the UNIVERSE next door
the UNPLEASANT profession of jonathan hoag
interview with a VAMPIRE
lucky star and the oceans of VENUS
the satanic VERSES
VERY far away from anywhere else
robot VISIONS
the cat who WALKS through walls
the cat who walks through WALLS
the lion the witch and the WARDROBE
the cat WHO walks through walls
i know WHY the caged bird sings
i WILL fear no evil
the lion the WITCH and the wardrobe
the WIZARD of oz
the scent of a WOMAN
WOMAN on the edge of time
still life with WOODPECKER
a WORLD of ideas
the WORLD according to garp
a connecticut YANKEE in king arthurs court
YES i can
portrait of the artist as a YOUNG man
count ZERO

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

Post by boatfish »

Thx very much.
I have solved it!

watershed
New poster
Posts: 13
Joined: Thu Aug 05, 2004 9:14 am

Post by watershed »

I tested those data
but I still got WA
who can help me
thanks....

Code: Select all

...cut...

ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

#123, If you get AC, please try this input.

Post by ImLazy »

What's the out put of this input?

Code: Select all

a
::
I am a Man
I am a mAn
I am a maN
I mean, the problemset says:"Case (upper or lower) is irrelevant when determining if a word is to be ignored." But it doesn't tell us whether case is relevant when determining if Man, mAn and maN are the same key word.
OK, if it is really relevant, then how about the order of these three words?
Maybe I misunderstand the problem for my poor English.
The reason why I have this suspicion is I get WA even though I get the right answer on this so long input:

Code: Select all

the
and
as
for
this
that
with
of
is
a
i
an
at
at
an
it
on
of
in
to
::
Fire in the Streets 
Chaos 
A troubled Feast 
Amerika 
A World of Ideas 
Out of Africa 
Death of a Salesman 
Farewell Anatolia 
Paradise Lost 
Paradise Regained 
The Descent of Man 
The Ascent of Man 
The Scent of a Woman 
Yes I Can 
Airport 
Hotel 
Roots 
Woman On The Edge of Time 
The Bean Trees 
Song of Solomon 
The Phantom Tollbooth 
I Know Why the Caged Bird Sings 
Animal Dreams 
The Old Man and The Sea 
Saint Maybe 
The Sum of All Fears 
Red Storm Rising 
Another Fine Myth 
Penguin Dreams and Stranger Things 
To Kill a Mockingbird 
The Adventures of Huckleberry Finn 
Heart of Darkness 
Anne of Green Gables 
The Lion the Witch and the Wardrobe 
Pride and Prejudice 
The Bell Jar 
Happy Are the Peacemakers 
The Sun Also Rises 
Portrait of The Artist As a Young Man 
Sons and Lovers 
A Dolls House 
The Scarlet Letter 
Second Foundation 
Lucky Star And the Oceans of Venus 
The Gods Themselves 
Robot Visions 
Foundations Edge 
Foundation 
Nightfall and Other Stories 
Very Far Away From Anywhere Else 
Time Enough For Love 
Beyond This Horizon 
Double Star 
The Moon is a Harsh Mistress 
Time for the Stars 
The Unpleasant Profession of Jonathan Hoag 
The Day After Tomorrow 
Citizen of the Galaxy 
Glory Road 
I Will Fear No Evil 
Space Cadet 
The Cat Who Walks Through Walls 
Neuromancer 
Burning Chrome 
Count Zero 
Islands in the Net 
Stranger in a Strange Land 
The Collapsing Universe 
I Sing the Body Electric 
Timeless Stories for Today and Tomorrow 
As On a Darkling Plain 
Still Life With Woodpecker 
The Color Purple 
Curoious George 
The Catcher in the Rye 
The Wizard of Oz 
A Connecticut Yankee in King Arthurs Court 
One Fish Two Fish Red Fish Blue Fish 
Eaters of the Dead 
Communist Manifesto 
Hop On Pop
Surprised by Joy
Lost in the Cosmos
The Universe Next Door
The Hiding Place
A Prayer for Owen Meany
A Tale of Two Cities
Interview with a Vampire
The World According to Garp
On Her Majestys Secret Service
Slaughterhouse Five
The Firm
Go Tell it on the Mountain
A Man is a Man but Bubblesort IS A DOG
The Quality School
The Satanic Verses
The Bone People
The Snow Leopard
My output:

Code: Select all

the world ACCORDING to garp 
the ADVENTURES of huckleberry finn 
out of AFRICA 
the day AFTER tomorrow 
AIRPORT 
the sum of ALL fears 
the sun ALSO rises 
AMERIKA 
farewell ANATOLIA 
ANIMAL dreams 
ANNE of green gables 
ANOTHER fine myth 
very far away from ANYWHERE else 
happy ARE the peacemakers 
a connecticut yankee in king ARTHURS court 
portrait of the ARTIST as a young man 
the ASCENT of man 
very far AWAY from anywhere else 
the BEAN trees 
the BELL jar 
BEYOND this horizon 
i know why the caged BIRD sings 
one fish two fish red fish BLUE fish 
i sing the BODY electric 
the BONE people 
a man is a man but BUBBLESORT is a dog 
BURNING chrome 
a man is a man BUT bubblesort is a dog 
surprised BY joy 
space CADET 
i know why the CAGED bird sings 
yes i CAN 
the CAT who walks through walls 
the CATCHER in the rye 
CHAOS 
burning CHROME 
a tale of two CITIES 
CITIZEN of the galaxy 
the COLLAPSING universe 
the COLOR purple 
COMMUNIST manifesto 
a CONNECTICUT yankee in king arthurs court 
lost in the COSMOS 
COUNT zero 
a connecticut yankee in king arthurs COURT 
CUROIOUS george 
as on a DARKLING plain 
heart of DARKNESS 
the DAY after tomorrow 
eaters of the DEAD 
DEATH of a salesman 
the DESCENT of man 
a man is a man but bubblesort is a DOG 
a DOLLS house 
the universe next DOOR 
DOUBLE star 
animal DREAMS 
penguin DREAMS and stranger things 
EATERS of the dead 
woman on the EDGE of time 
foundations EDGE 
i sing the body ELECTRIC 
very far away from anywhere ELSE 
time ENOUGH for love 
i will fear no EVIL 
very FAR away from anywhere else 
FAREWELL anatolia 
i will FEAR no evil 
the sum of all FEARS 
a troubled FEAST 
another FINE myth 
the adventures of huckleberry FINN 
FIRE in the streets 
the FIRM 
one FISH two fish red fish blue fish 
one fish two FISH red fish blue fish 
one fish two fish red FISH blue fish 
one fish two fish red fish blue FISH 
slaughterhouse FIVE 
second FOUNDATION 
FOUNDATION 
FOUNDATIONS edge 
very far away FROM anywhere else 
anne of green GABLES 
citizen of the GALAXY 
the world according to GARP 
curoious GEORGE 
GLORY road 
GO tell it on the mountain 
the GODS themselves 
anne of GREEN gables 
HAPPY are the peacemakers 
the moon is a HARSH mistress 
HEART of darkness 
on HER majestys secret service 
the HIDING place 
the unpleasant profession of jonathan HOAG 
HOP on pop 
beyond this HORIZON 
HOTEL 
a dolls HOUSE 
the adventures of HUCKLEBERRY finn 
a world of IDEAS 
INTERVIEW with a vampire 
ISLANDS in the net 
the bell JAR 
the unpleasant profession of JONATHAN hoag 
surprised by JOY 
to KILL a mockingbird 
a connecticut yankee in KING arthurs court 
i KNOW why the caged bird sings 
stranger in a strange LAND 
the snow LEOPARD 
the scarlet LETTER 
still LIFE with woodpecker 
the LION the witch and the wardrobe 
paradise LOST 
LOST in the cosmos 
time enough for LOVE 
sons and LOVERS 
LUCKY star and the oceans of venus 
on her MAJESTYS secret service 
the descent of MAN 
the ascent of MAN 
the old MAN and the sea 
portrait of the artist as a young MAN 
a MAN is a man but bubblesort is a dog 
a man is a MAN but bubblesort is a dog 
communist MANIFESTO 
saint MAYBE 
a prayer for owen MEANY 
the moon is a harsh MISTRESS 
to kill a MOCKINGBIRD 
the MOON is a harsh mistress 
go tell it on the MOUNTAIN 
another fine MYTH 
islands in the NET 
NEUROMANCER 
the universe NEXT door 
NIGHTFALL and other stories 
i will fear NO evil 
lucky star and the OCEANS of venus 
the OLD man and the sea 
ONE fish two fish red fish blue fish 
nightfall and OTHER stories 
OUT of africa 
a prayer for OWEN meany 
the wizard of OZ 
PARADISE lost 
PARADISE regained 
happy are the PEACEMAKERS 
PENGUIN dreams and stranger things 
the bone PEOPLE 
the PHANTOM tollbooth 
the hiding PLACE 
as on a darkling PLAIN 
hop on POP 
PORTRAIT of the artist as a young man 
a PRAYER for owen meany 
pride and PREJUDICE 
PRIDE and prejudice 
the unpleasant PROFESSION of jonathan hoag 
the color PURPLE 
the QUALITY school 
RED storm rising 
one fish two fish RED fish blue fish 
paradise REGAINED 
the sun also RISES 
red storm RISING 
glory ROAD 
ROBOT visions 
ROOTS 
the catcher in the RYE 
SAINT maybe 
death of a SALESMAN 
the SATANIC verses 
the SCARLET letter 
the SCENT of a woman 
the quality SCHOOL 
the old man and the SEA 
SECOND foundation 
on her majestys SECRET service 
on her majestys secret SERVICE 
i SING the body electric 
i know why the caged bird SINGS 
SLAUGHTERHOUSE five 
the SNOW leopard 
song of SOLOMON 
SONG of solomon 
SONS and lovers 
SPACE cadet 
lucky STAR and the oceans of venus 
double STAR 
time for the STARS 
STILL life with woodpecker 
nightfall and other STORIES 
timeless STORIES for today and tomorrow 
red STORM rising 
stranger in a STRANGE land 
penguin dreams and STRANGER things 
STRANGER in a strange land 
fire in the STREETS 
the SUM of all fears 
the SUN also rises 
SURPRISED by joy 
a TALE of two cities 
go TELL it on the mountain 
the gods THEMSELVES 
penguin dreams and stranger THINGS 
the cat who walks THROUGH walls 
woman on the edge of TIME 
TIME enough for love 
TIME for the stars 
TIMELESS stories for today and tomorrow 
timeless stories for TODAY and tomorrow 
the phantom TOLLBOOTH 
the day after TOMORROW 
timeless stories for today and TOMORROW 
the bean TREES 
a TROUBLED feast 
one fish TWO fish red fish blue fish 
a tale of TWO cities 
the collapsing UNIVERSE 
the UNIVERSE next door 
the UNPLEASANT profession of jonathan hoag 
interview with a VAMPIRE 
lucky star and the oceans of VENUS 
the satanic VERSES 
VERY far away from anywhere else 
robot VISIONS 
the cat who WALKS through walls 
the cat who walks through WALLS 
the lion the witch and the WARDROBE 
the cat WHO walks through walls 
i know WHY the caged bird sings 
i WILL fear no evil 
the lion the WITCH and the wardrobe 
the WIZARD of oz 
the scent of a WOMAN 
WOMAN on the edge of time 
still life with WOODPECKER 
a WORLD of ideas 
the WORLD according to garp 
a connecticut YANKEE in king arthurs court 
YES i can 
portrait of the artist as a YOUNG man 
count ZERO 
I'm sure this is the right answer because some other one who gets AC has the same output as mine.
Last edited by ImLazy on Thu Feb 03, 2005 5:49 pm, edited 1 time in total.
I stay home. Don't call me out.

ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

And this is my code:

Code: Select all

#include<stdio.h>
#include<string.h>

#define MaxKey 250
#define MaxTitle 100

char ignore[30][11],
     key[MaxKey][20];

int cnt_ignore=0,
    cnt_key=0;

int insert(char *p)
{
  int i,j;
  if(cnt_key==0)
  {
    strcpy(key[cnt_key],p);
    cnt_key++;
  }
  else
  {
    i=0;
    while(strcmp(key[i],p)<0 && i<cnt_key)
      i++;
    if(strcmp(key[i],p)!=0)
    {
      for(j=cnt_key-1;j>=i;j--)
        strcpy(key[j+1],key[j]);
      strcpy(key[i],p);
      cnt_key++;
    }
  }
  return 0;
}

int ifIgnore(char *p)
{
  int i;
  for(i=0;i<cnt_ignore;i++)
    if(strcmp(ignore[i],p)==0)
      return 1;
  return 0;
}

int toUpper(char *p)
{
  while(*p!='\0')
  {
    if(*p>='a' && *p<='z')
      *p-=32;
    p++;
  }
  return 0;
}

int toLower(char *p)
{
  while(*p!='\0')
  {
    if(*p>='A' && *p<='Z')
      *p+=32;
    p++;
  }
  return 0;
}

int main()
{
  char title[MaxTitle][15][20],
       line[100],
       temp[20];
  int cnt_title=0,
      cnt_word[MaxTitle],
      i,j,k,l;
  while(1)
  {
    gets(ignore[cnt_ignore]);
    if(strcmp(ignore[cnt_ignore],"::")==0)
      break;
    else
      cnt_ignore++;
  }
  while(gets(line)!=NULL)
  {
    i=j=k=0;
    while(1)
    {
      if((line[j]<'a' || line[j]>'z')&&(line[j]<'A' || line[j]>'Z') )
      {
        if(k!=0)
        {
          temp[k]='\0';
          strcpy(title[cnt_title][i],temp);
          toLower(title[cnt_title][i]);
          if(ifIgnore(title[cnt_title][i])==0)
            insert(title[cnt_title][i]);
          i++;
          k=0;
        }
        if(line[j]=='\0')
          break;
      }
      else
      {
        temp[k]=line[j];
        k++;
      }
      j++;
    }
    cnt_word[cnt_title]=i;
    cnt_title++;
  }
  for(i=0;i<cnt_key;i++)
    for(j=0;j<cnt_title;j++)
      for(k=0;k<cnt_word[j];k++)
        if(strcmp(title[j][k],key[i])==0)
        {
          for(l=0;l<k;l++)
            printf("%s ",title[j][l]);
          toUpper(title[j][k]);
          printf("%s ",title[j][k]);
          toLower(title[j][k]);
          for(l=k+1;l<cnt_word[j];l++)
            printf("%s ",title[j][l]);
          printf("\b\n");
        }
  return 0;
}
Last edited by ImLazy on Sat Feb 05, 2005 9:06 am, edited 4 times in total.
I stay home. Don't call me out.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Re: #123, If you get AC, please try this input.

Post by chunyi81 »

ImLazy wrote:What's the out put of this input?

Code: Select all

a
::
I am a Man
I am a mAn
I am a maN
My AC program's output:

Code: Select all

i AM a man
i AM a man
i AM a man
I am a man
I am a man
I am a man
i am a MAN
i am a MAN
i am a MAN

ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

Thanks. But now I get confused why I get WA.
I stay home. Don't call me out.

ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

Dear chunyi81, would like to tell me whether your output for the long input above is identical as mine.
I stay home. Don't call me out.

Post Reply

Return to “Volume 1 (100-199)”