10295 - Hay Points
Posted: Mon Jul 22, 2002 4:39 pm
It says the dollars value are real numbers, so how to output them?
a dollar value (a real number between 0 and 1,000,000)
Code: Select all
Does that mean that point is a floating point number ?
Then how come the sample output is without decimal point...
(Is it because the sample input produces result without fractions !!!)
SECONDLY,
what is the size of the array to take per input line ?
[I use some 10000000 bytes char array and gets RE :(]
Please clarify ... thanks.
Code: Select all
st = new StringTokenizer(readLine());
String s = st.nextToken();
int val = parseInt(st.nextToken());
list.put(s, new Integer(val));
Code: Select all
st = new StringTokenizer(readLine());
list.put(st.nextToken(), new Integer(parseInt(st.nextToken())));
05837124_24.c:8: ANSI C++ forbids data member `word' with same name as enclosing class
05837124_24.c:10: confused by earlier errors, bailing out
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct no
{
char pala[16];
long value;
}dictionary;
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo );
void Quick(dictionary tabela[], unsigned inf, unsigned sup);
void QuickSort(dictionary tabela[], unsigned nElem);
int EncontraIndice(char palavra[], dictionary tabela[], int tam);
int main()
{
dictionary words[1000];
char aux[16];
char palavra[16];
long aux2;
long score;
int help;
int numberWords;
int numberJobs;
int i = 0;
scanf("%d %d", &numberWords, &numberJobs);
while(i < numberWords)
{
scanf("%s %ld", words[i].pala, &words[i].value);
i++;
}
if(strcmp(words[0].pala, words[1].pala) < 0 )
{
strcpy(aux, words[1].pala);
aux2 = words[1].value;
strcpy(words[1].pala, words[0].pala);
words[1].value = words[0].value;
strcpy(words[0].pala, aux);
words[0].value = aux2;
}
QuickSort(words, numberWords);
i = 0;
while(i < numberJobs)
{
score = 0;
while(1)
{
scanf("%s", palavra);
if(!strcmp(palavra,"."))
{
break;
}
help = EncontraIndice(palavra, words, numberWords);
if(help == -1)
{
continue;
}
else{
score = score + words[help].value;
}
}
printf("%ld\n", score);
i++;
}
return(0);
}
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo )
{
char pivo[16];
long vpivo;
unsigned sobe, desce;
char aux[16];
int vaux;
strcpy(pivo,tabela[inf].pala);
vpivo = tabela[inf].value;
sobe = inf;
desce = sup;
while (sobe < desce) {
while (strcmp(tabela[sobe].pala, pivo) <= 0 && sobe < sup)
sobe++;
while (strcmp(tabela[desce].pala, pivo) > 0)
desce--;
if (sobe < desce) {
strcpy(aux, tabela[desce].pala);
vaux = tabela[desce].value;
strcpy(tabela[desce].pala, tabela[sobe].pala);
tabela[desce].value = tabela[sobe].value;
strcpy(tabela[sobe].pala, aux);
tabela[sobe].value = vaux;
}
}
strcpy(tabela[inf].pala, tabela[desce].pala);
tabela[inf].value = tabela[desce].value;
strcpy(tabela[desce].pala, pivo);
tabela[desce].value = vpivo;
*posPivo = desce;
}
void Quick(dictionary tabela[], unsigned inf, unsigned sup)
{
unsigned posPivo;
if (inf >= sup)
return;
Particiona(tabela, inf, sup, &posPivo);
Quick(tabela, inf, posPivo-1);
Quick(tabela, posPivo+1, sup);
}
void QuickSort(dictionary tabela[], unsigned nElem)
{
Quick(tabela, 0, nElem-1);
}
int EncontraIndice(char palavra[], dictionary chaves[], int tam)
{
int limiteInf, limiteSup, metade;
limiteInf = 0;
limiteSup = tam - 1;
while(limiteInf <= limiteSup) {
metade = (limiteInf + limiteSup)/2;
if (!strcmp(chaves[metade].pala, palavra))
{
return metade;
}
if (strcmp(palavra, chaves[metade].pala) < 0)
limiteSup = metade - 1;
else
limiteInf = metade + 1;
}
return -1;
}
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct no
{
char pala[16];
long value;
}dictionary;
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo );
void Quick(dictionary tabela[], unsigned inf, unsigned sup);
void QuickSort(dictionary tabela[], unsigned nElem);
int EncontraIndice(char palavra[], dictionary tabela[], int tam);
int main()
{
dictionary words[1000];
char aux[16];
char palavra[16];
long aux2;
long score;
int help;
int numberWords;
int numberJobs;
int i = 0;
scanf("%d %d", &numberWords, &numberJobs);
while(i < numberWords)
{
scanf("%s %ld", words[i].pala, &words[i].value);
i++;
}
if(strcmp(words[0].pala, words[1].pala) < 0 )
{
strcpy(aux, words[1].pala);
aux2 = words[1].value;
strcpy(words[1].pala, words[0].pala);
words[1].value = words[0].value;
strcpy(words[0].pala, aux);
words[0].value = aux2;
}
QuickSort(words, numberWords);
i = 0;
while(i < numberJobs)
{
score = 0;
while(1)
{
scanf("%s", palavra);
if(!strcmp(palavra,"."))
{
break;
}
help = EncontraIndice(palavra, words, numberWords);
if(help == -1)
{
continue;
}
else{
score = score + words[help].value;
}
}
printf("%ld\n", score);
i++;
}
return(0);
}
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo )
{
char pivo[16];
long vpivo;
unsigned sobe, desce;
char aux[16];
int vaux;
strcpy(pivo,tabela[inf].pala);
vpivo = tabela[inf].value;
sobe = inf;
desce = sup;
while (sobe < desce) {
while (strcmp(tabela[sobe].pala, pivo) <= 0 && sobe < sup)
sobe++;
while (strcmp(tabela[desce].pala, pivo) > 0)
desce--;
if (sobe < desce) {
strcpy(aux, tabela[desce].pala);
vaux = tabela[desce].value;
strcpy(tabela[desce].pala, tabela[sobe].pala);
tabela[desce].value = tabela[sobe].value;
strcpy(tabela[sobe].pala, aux);
tabela[sobe].value = vaux;
}
}
strcpy(tabela[inf].pala, tabela[desce].pala);
tabela[inf].value = tabela[desce].value;
strcpy(tabela[desce].pala, pivo);
tabela[desce].value = vpivo;
*posPivo = desce;
}
void Quick(dictionary tabela[], unsigned inf, unsigned sup)
{
unsigned posPivo;
if (inf >= sup)
return;
Particiona(tabela, inf, sup, &posPivo);
Quick(tabela, inf, posPivo-1);
Quick(tabela, posPivo+1, sup);
}
void QuickSort(dictionary tabela[], unsigned nElem)
{
Quick(tabela, 0, nElem-1);
}
int EncontraIndice(char palavra[], dictionary chaves[], int tam)
{
int limiteInf, limiteSup, metade;
limiteInf = 0;
limiteSup = tam - 1;
while(limiteInf <= limiteSup) {
metade = (limiteInf + limiteSup)/2;
if (!strcmp(chaves[metade].pala, palavra))
{
return metade;
}
if (strcmp(palavra, chaves[metade].pala) < 0)
limiteSup = metade - 1;
else
limiteInf = metade + 1;
}
return -1;
}