10745 - Dominant Strings
Moderator: Board moderators
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
hmm
Sorry! I never used or heard of seekeof(), so I cannot comment. You don't need to use eof() to check whether file has ended so ...
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
jmm
a) tell me the problem u r solving
b) Do you use C language or anything else?
b) Do you use C language or anything else?
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
seekeof is a Pascal function, as is eof, so the language NightFir is referring to is Pascal (you should have written that in your posting!).
It's funny that the judge forbids this function, because it's a perfectly legal (though a bit unusual) function to scan an input stream (not only files but also the standard input stream).
I would be practical about it and only use eof in your programs and forget about seekeof when solving UVA problems.
It's funny that the judge forbids this function, because it's a perfectly legal (though a bit unusual) function to scan an input stream (not only files but also the standard input stream).
I would be practical about it and only use eof in your programs and forget about seekeof when solving UVA problems.
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
Re: jmm
I was going in completely wrong direction because never realized that your language is PASCAL. Can't blame myself for not remembering about seekeof because I used to program in Pascal 8 years ago.shahriar_manzoor wrote:a) tell me the problem u r solving
b) Do you use C language or anything else?
-
- Learning poster
- Posts: 72
- Joined: Tue May 30, 2006 5:57 pm
- Location: bangladesh
Re: 10745 - Dominant Strings
I was stuck in this problem several hours.
After generating some random inputs, I got the error.
Here it is:
Input:
AC output:
Also try :
After generating some random inputs, I got the error.
Here it is:
Input:
Code: Select all
a
ab
Code: Select all
ab
Code: Select all
ab
a
Mak
Help me PLZ!!
Help me PLZ!!
10745 - Dominant Strings RE
Code: Select all
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <time.h>
using namespace std;
int intersec(string pal1, string pal2);
int main(int argc, char *argv[]) {
//clock_t tin, tf;
string line;
vector<string> palabras;
vector<string> palDominantes;
//tin= clock ();
while(cin>>line) {
palDominantes.push_back(line);
sort(line.begin(), line.end());
palabras.push_back(line);
}
int tamPal = palabras.size();
for( int i = 0; i < tamPal; i++) {
for(int j = i+1; j < tamPal; j++) {
if(palabras[j] != palabras[i]) {
if(palabras[i].size() < palabras[j].size()) {
if(intersec(palabras[j],palabras[i])){
palabras.erase(palabras.begin() + i);
//palDominantes.erase(palDominantes.begin() + i);
i--;
tamPal--;
}
}
else if(palabras[i].size() > palabras[j].size())
if(intersec(palabras[i], palabras[j])){
palabras.erase(palabras.begin() + j);
//palDominantes.erase(palDominantes.begin() + j);
j--;
tamPal--;
}
}
}
}
sort(palDominantes.begin(),palDominantes.end());
for(unsigned int i = 0; i < palDominantes.size(); i++)
cout<<palDominantes[i]<<endl;
//tf = clock();
//cout<<(double)(tf - tin)/CLOCKS_PER_SEC*1000.0<<endl;
getchar();
return 0;
}
int intersec(string pal1, string pal2) {
int c1=0, c2=0;
int tam1 = pal1.size(), tam2=pal2.size();
//pal1 seria la palabra de mayor tamaño
while(((tam2 - c2) <= (tam1 - c1)) && (c2 < tam2)) {
if(pal1[c1] == pal2[c2])
c2++;
c1++;
}
if(c2 == tam2)
return 1;
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10745 - Dominant Strings
Check input and AC output for thousands of problems on uDebug!