- UID
- 412887
- 在线时间
- 0 小时
- 最后登录
- 1970-1-1
- 注册时间
- 2013-3-26
- 宅魂
- 749 点
- 贡献
- 100 点
- 宅币
- 15790 枚
- 灵石
- 0 块
- 元气(技能点)
- 3 点
- 活跃
- 0 ℃
- 听众
- 6
- 收听
- 0
该用户从未签到
第一章
- 积分
- 18487
|

楼主 |
发表于 2013-5-21 09:44:03
|
显示全部楼层
现在用 字符串存,然后读取指定下标。 服务器判WA。求解。
[mw_shl_code=c,true]#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define max 1001
typedef struct Node
{
int data;
char en[max];
char cn[max*10];
struct Node *next;
}LNode,*List;
int List_add(List L,char *a)
{
int ok=0;
while(L->next!=NULL)
{
L=L->next;
if(strcmp(L->en,a)==0)
{
ok=1;
break;
}
}
if(ok==1)
{
char str[10];
scanf("%s",str);
strcat(L->cn,str);
}
else
{
List New=(LNode*)malloc(sizeof(LNode));
strcpy(New->en,a);scanf("%s",New->cn);
New->next=L->next;
L->next=New;
}
}
int List_show(List L,char *a)
{
int i=0,n;
char str[10];
scanf("%d",&n);
while(L->next!=NULL)
{
L=L->next;
if(strcmp(L->en,a)==0)
{
i=1;
int len=strlen(L->cn);
if(n>len/2)
str[0]=L->cn[len-2],str[1]=L->cn[len-1],str[2]='\0';
else
str[0]=L->cn[2*n-2],str[1]=L->cn[2*n-1],str[2]='\0';
printf("%s\n",str);return 0;
}
}
if(i==0)printf("NO\n");
}
int main()
{
List L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
char a[max];
while(scanf("%s",a)!=EOF)
{
if(strcmp(a,"end")==0)break;
List_add(L,a);
}
while(scanf("%s",a)!=EOF)
{
if(strcmp(a,"end")==0)break;
List_show(L,a);
}
return 0;
}
[/mw_shl_code] |
评分
-
查看全部评分
|