10420 - List of Conquests
Moderator: Board moderators
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Ghust_omega, just try to create any dynamic data structure. Not always static tables are enough ![:-)](./images/smilies/icon_smile.gif)
Best regards
DM
![:-)](./images/smilies/icon_smile.gif)
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh
Hi, anyone who needs helps in this problem can check this out....nothing much but may help u.
I was getting WA for whole night(u know how it feels
) and in the morning i just got AC
....
Here is some I/O...u can test it...[c]15
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
Bangladesh Hasan
Bangladesh Bijon Khaled Jaman
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
India Saiket podder
India Partha Sarker
Bangladesh Hasan Ahmed
Bangladesh Bijon Khaled Jaman
Australia Anil
Bangladesh Shoikot
Barma Asma
Bangladesh Saiket[/c]
Output:
Australia 1
Bangladesh 6
Barma 1
India 2
I was getting WA for whole night(u know how it feels
![:evil:](./images/smilies/icon_evil.gif)
![:D](./images/smilies/icon_biggrin.gif)
Here is some I/O...u can test it...[c]15
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
Bangladesh Hasan
Bangladesh Bijon Khaled Jaman
Bangladesh Jalal Uddin
Bangladesh Jalal Uddin
India Saiket podder
India Partha Sarker
Bangladesh Hasan Ahmed
Bangladesh Bijon Khaled Jaman
Australia Anil
Bangladesh Shoikot
Barma Asma
Bangladesh Saiket[/c]
Output:
Australia 1
Bangladesh 6
Barma 1
India 2
Jalal : AIUB SPARKS
- Ali Arman Tamal
- Learning poster
- Posts: 76
- Joined: Sat Jan 15, 2005 5:04 pm
- Location: Dhaka
- Contact:
Hello Everyone !
I think codemaker is wrong. I solved the code without considering any duplicate women name and still got AC.
My output for the codemaker's input is
Australia 1
Bangladesh 11
Barma 1
India 2
Since the judge doesn't seem to give any duplicate name, so considering duplicate or not considering will lead to the same answer !!
And Ghust Omega, if you still haven't got AC, watch this:
1. There will not be more than 201 different countries. My AC code couldn't handle more than 201 different countries.
2. You can use array of structure like this:
struct data
{
char name[80];
int freq;
};
struct data country[201];
and later use it for other operation
Hope it helps!!
![:)](./images/smilies/icon_smile.gif)
I think codemaker is wrong. I solved the code without considering any duplicate women name and still got AC.
![:wink:](./images/smilies/icon_wink.gif)
My output for the codemaker's input is
Australia 1
Bangladesh 11
Barma 1
India 2
Since the judge doesn't seem to give any duplicate name, so considering duplicate or not considering will lead to the same answer !!
![:wink:](./images/smilies/icon_wink.gif)
And Ghust Omega, if you still haven't got AC, watch this:
1. There will not be more than 201 different countries. My AC code couldn't handle more than 201 different countries.
2. You can use array of structure like this:
struct data
{
char name[80];
int freq;
};
struct data country[201];
and later use it for other operation
![:)](./images/smilies/icon_smile.gif)
Hope it helps!!
10420 Runtime error
Sir John Leparro (104-20) has died on the march 20th of the year 2006 with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before being crashed by an ongoing heavy truck, he ran for 0.014 seconds on the streets of downtown of UVa. His last wish was someone will tell his innocent relatives about why he had an invalid memory reference problem!
We mourn for Sir John Leparro, but right now, invalid memory reference is bugging us very much! Instead of a proper hashing, all the program did is a proper crashing~!
Invalid memory reference
![:o](./images/smilies/icon_eek.gif)
Before being crashed by an ongoing heavy truck, he ran for 0.014 seconds on the streets of downtown of UVa. His last wish was someone will tell his innocent relatives about why he had an invalid memory reference problem!
![:cry:](./images/smilies/icon_cry.gif)
We mourn for Sir John Leparro, but right now, invalid memory reference is bugging us very much! Instead of a proper hashing, all the program did is a proper crashing~!
![:P](./images/smilies/icon_razz.gif)
Code: Select all
/*
* 10420 List of Conquests
* submission 1 RE
* coded at 1004pm march 20, 2006
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define PRIME 3001
#define MULTIPLIER 37
#define NHASH PRIME
typedef struct Country Country;
struct Country {
char name[76];
int count;
int next;
};
Country country[3001];
int extra=2003;
void init() {
for(int i=0;i<=PRIME;i++) {
strcpy(country[i].name,"");
country[i].count=0;
country[i].next=-1;
}
}
void print() {
for(int i=0;i<=PRIME;i++) {
if(strcmp(country[i].name,"")!=0) {
printf("%s %d\n",country[i].name,country[i].count);
}
}
}
int compare(const void *va, const void *vb) {
Country *a,*b;
a=(Country *)va;
b=(Country *)vb;
return strcmp(a->name,b->name);
}
unsigned int hash(char *str) {
unsigned int h=0;
int len=strlen(str);
for(int i=0;i<len;i++)
h=MULTIPLIER*h + str[i];
return h % NHASH;
}
void add(char *str) {
int h=hash(str);
if(!strcmp(country[h].name,"")) {
strcpy(country[h].name,str);
country[h].count++;
}else if(!strcmp(country[h].name,str)) {
country[h].count++;
}else {
while(country[h].next!=-1) {
h=country[h].next;
if(!strcmp(country[h].name,str)) {
country[h].count++;
h=-1;
break;
}
}
if(h!=-1) {
country[h].next=++extra;
strcpy(country[extra].name,str);
country[extra].count++;
}
}
}
int main() {
char line[100];
char word[76];
int n;
int i,j;
while(scanf("%d",&n)==1) {
init();
gets(line);
for(i=0;i<n;i++) {
gets(line);
j=0;
while(line[j]!=' ') {
word[j]=line[j];
j++;
}
word[j]='\0';
add(word);
}
qsort(country,PRIME,sizeof(country[0]),compare);
print();
}
}
fahim
#include <smile.h>
#include <smile.h>
-
- Experienced poster
- Posts: 151
- Joined: Tue Nov 16, 2004 7:23 pm
- Location: Norway
- Contact:
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm