| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么会错呢?bow#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
int result[50];
char name[50];
int n; int m;
struct student_node
{
char name[50];
int score;
student_node* next;
};
student_node* student_list[1000];
void init()
{
memset(result, 0, sizeof(result));
n = 0;
for(int i = 0; i < 1000; i++)
student_list[i] = NULL;
}
int get_hash(char* key)
{
unsigned long h =0 ;
while (*key){
h = (h <<4) + *key++;
unsigned long g = h &0xF0000000L;
if (g)h^=g>>24;
h&=~g;
}
return h & 1000;
}
void read_name()
{
for(int i = 0; i < n; i++)
{
int pos = 0; char c;
memset(name, '\0', sizeof(name));
while((c = getchar()) != '\n')
name[pos++] = c;
int hash_value = get_hash(name);
student_node* temp = (student_node*)malloc(sizeof(student_node));
memset(temp->name, '\0', sizeof(temp->name));
temp->score = 0;
temp->next = NULL;
memcpy(temp->name, name, sizeof(name));
student_node* p = student_list[hash_value];
student_list[hash_value] = temp;
temp->next = p;
}
}
void rank_student(int i)
{
for(int k = 0; k < n; k++)
{
int score;
char buf[50]; memset(buf, '\0', sizeof(buf));
scanf("%d ", &score);
int pos = 0; char c;
int name_start = 0;
while((c = getchar()) != '\n')
buf[pos++] = c;
int hash_value = get_hash(buf);
student_node* p = student_list[hash_value];
while(strcmp(buf, p->name) != 0)
p = p->next;
p->score += score;
}
int index_hash = get_hash("Li Ming");
student_node* temp = student_list[index_hash];
while(strcmp(temp->name, "Li Ming") != 0)
temp = temp->next;
int index_score = temp->score;
int count = 1;
for(int k = 0; k < 1000; k++)
{
if(student_list[k] != NULL)
{
student_node* p = student_list[k];
while(p != NULL)
{
if(p->score > index_score)
count++;
p = p->next;
}
}
}
printf("%d\n", count);
}
int main(int argc, char* argv)
{
init();
scanf("%d\n", &n);
read_name();
scanf("%d\n", &m);
for(int i = 0; i < m; i++)
rank_student(i);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator