hmm
Posted: Thu Feb 17, 2005 3:16 pm
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 ...
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?
Code: Select all
a
ab
Code: Select all
ab
Code: Select all
ab
a
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;
}