| ||||||||||
| 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 | |||||||||
求高手帮忙指点一下#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node{
char name[16]; //存放单词
long val; //存放单词的价值
} job[1000];
int m,n;
char s[16];
double value(char *s){ //此函数返回查询的单词的价值
int i;
for (i=0;i<m;i++)
if (strcmp(job[i].name,s)==0) return job[i].val;
return 0;
}
main(){
int i;
double sum[100];
while (scanf("%d %d",&m,&n) != EOF){
for (i=0;i<m;i++)
scanf("%s %ld",job[i].name,&job[i].val); //读入前m行的单词极其价值
for (i=0;i<n;i++){
sum[i]=0;
while(scanf("%s",s)&&strcmp(s,".")!=0) //计算每段文章的总价值
sum[i]+=value(s);
}
}
for (i=0;i<n;i++) printf("%.0f\n",sum[i]); //输出
return 0;
}
主要的思想就是利用scanf每次读入后面文章的一个单词然后线性查找单词表,我觉得程序应该没有错误,但总是wrong answer 求大人帮忙
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator