10745 - Dominant Strings

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

Moderator: Board moderators

shahriar_manzoor
System administrator & Problemsetter
Posts: 399
Joined: Sat Jan 12, 2002 2:00 am

hmm

Post by shahriar_manzoor »

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 ...
NightFir
New poster
Posts: 5
Joined: Thu Feb 17, 2005 2:01 pm

Post by NightFir »

" You don't need to use eof() to check whether file has ended so ..."
If I don't use "eof",what else can I do to check whether file has ended?
NightFir
New poster
Posts: 5
Joined: Thu Feb 17, 2005 2:01 pm

Post by NightFir »

" You don't need to use eof() to check whether file has ended so ..."
If I don't use "eof",what else can I do to check whether file has ended?
shahriar_manzoor
System administrator & Problemsetter
Posts: 399
Joined: Sat Jan 12, 2002 2:00 am

jmm

Post by shahriar_manzoor »

a) tell me the problem u r solving
b) Do you use C language or anything else?
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

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.
shahriar_manzoor
System administrator & Problemsetter
Posts: 399
Joined: Sat Jan 12, 2002 2:00 am

Re: jmm

Post by shahriar_manzoor »

shahriar_manzoor wrote:a) tell me the problem u r solving
b) Do you use C language or anything else?
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.
mak(cse_DU)
Learning poster
Posts: 72
Joined: Tue May 30, 2006 5:57 pm
Location: bangladesh

Re: 10745 - Dominant Strings

Post by mak(cse_DU) »

I was stuck in this problem several hours.
After generating some random inputs, I got the error.
Here it is:
Input:

Code: Select all

a
ab
AC output:

Code: Select all

ab
Also try :

Code: Select all

ab
a
Mak
Help me PLZ!!
nlisi2012
New poster
Posts: 1
Joined: Thu Apr 26, 2012 2:57 am

10745 - Dominant Strings RE

Post by nlisi2012 »

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;
}
i have runtime error and i don't know why? i'm going crazy! i made everithing kind of changes but i cant receive AC
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10745 - Dominant Strings

Post by brianfry713 »

Doesn't match the sample I/O.

http://ideone.com/NtAjx
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 107 (10700-10799)”