金牌、银牌、铜牌(C语言)
来源:互联网 发布:穿越火线mac官方下载 编辑:程序博客网 时间:2024/04/27 14:58
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ns
{
char name[21];
int m;
struct ns *next;
};
struct ns *scan(int n)
{
int i;
struct ns *head,*tail,*p;
head=malloc(sizeof(struct ns));
head->next=NULL;
tail=head;
for(i=0;i<n;i++)
{
p=malloc(sizeof(struct ns));
scanf("%s%d",p->name,&p->m);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
void a(struct ns *head,struct ns *p)
{
struct ns *t;
/*p=malloc(sizeof(struct ns));
p->next=NULL;
scanf("%s%d",p->name,&p->m);*/
t=head;
while(t->next!=NULL)
{
if(t->next->m>=p->m)
t=t->next;
else
break;
}
p->next=t->next;
t->next=p;
}
void q(struct ns *head)
{
char name[21];
struct ns *t;
t=head;
scanf("%s",name);
while(t->next!=NULL)
{
if(strcmp(t->next->name,name)==0)
{
t->next=t->next->next;break;
}
t=t->next;
}
}
void c(struct ns *head)
{
char name[21];
int x;
struct ns *t,*m;
scanf("%s%d",name,&x);
t=head;
while (t->next!=NULL)
{
if(strcmp(t->next->name,name)==0)
{
m=t->next;
t->next=t->next->next;break;
}
t=t->next;
}
m->next=NULL;m->m=m->m+x;
//printf("c%d",m->m);
a(head,m);
}
void s(struct ns *head)
{
struct ns *p;
p=head->next;
while (p!=NULL)
{
printf("%s %d\n",p->name,p->m);
p=p->next;
}
}
void o(struct ns *head,int paiming)
{
if(paiming==4)
return ;
int i,t;
struct ns *p;
p=head;
printf("#%d : %s",paiming,p->name);
i=1;
t=p->m;
p=p->next;
while(p!=NULL)
{
if(p->m==t&&i<=paiming)
{
printf(" %s",p->name);
t=p->m;
p=p->next;
}
else if(p->m!=t&&i<paiming)
{
printf(" %s",p->name);
t=p->m;
p=p->next;
i++;
}
else
break;
}
printf("\n");
paiming=paiming+1;
o(p,paiming);
}
int main()
{
int n;
char ch;
struct ns *head,*p;
scanf("%d",&n);
head=scan(n);
while(scanf("%c",&ch)!=EOF)
{
if(ch=='O')
{o(head->next,1);break;}
if(ch=='A')
{
p=malloc(sizeof(struct ns));
p->next=NULL;
scanf("%s%d",p->name,&p->m);
a(head,p);
}
if(ch=='Q')
q(head);
if(ch=='C')
c(head);
if(ch=='S')
s(head);
}
return 0;
}
#include <stdlib.h>
#include <string.h>
struct ns
{
char name[21];
int m;
struct ns *next;
};
struct ns *scan(int n)
{
int i;
struct ns *head,*tail,*p;
head=malloc(sizeof(struct ns));
head->next=NULL;
tail=head;
for(i=0;i<n;i++)
{
p=malloc(sizeof(struct ns));
scanf("%s%d",p->name,&p->m);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
void a(struct ns *head,struct ns *p)
{
struct ns *t;
/*p=malloc(sizeof(struct ns));
p->next=NULL;
scanf("%s%d",p->name,&p->m);*/
t=head;
while(t->next!=NULL)
{
if(t->next->m>=p->m)
t=t->next;
else
break;
}
p->next=t->next;
t->next=p;
}
void q(struct ns *head)
{
char name[21];
struct ns *t;
t=head;
scanf("%s",name);
while(t->next!=NULL)
{
if(strcmp(t->next->name,name)==0)
{
t->next=t->next->next;break;
}
t=t->next;
}
}
void c(struct ns *head)
{
char name[21];
int x;
struct ns *t,*m;
scanf("%s%d",name,&x);
t=head;
while (t->next!=NULL)
{
if(strcmp(t->next->name,name)==0)
{
m=t->next;
t->next=t->next->next;break;
}
t=t->next;
}
m->next=NULL;m->m=m->m+x;
//printf("c%d",m->m);
a(head,m);
}
void s(struct ns *head)
{
struct ns *p;
p=head->next;
while (p!=NULL)
{
printf("%s %d\n",p->name,p->m);
p=p->next;
}
}
void o(struct ns *head,int paiming)
{
if(paiming==4)
return ;
int i,t;
struct ns *p;
p=head;
printf("#%d : %s",paiming,p->name);
i=1;
t=p->m;
p=p->next;
while(p!=NULL)
{
if(p->m==t&&i<=paiming)
{
printf(" %s",p->name);
t=p->m;
p=p->next;
}
else if(p->m!=t&&i<paiming)
{
printf(" %s",p->name);
t=p->m;
p=p->next;
i++;
}
else
break;
}
printf("\n");
paiming=paiming+1;
o(p,paiming);
}
int main()
{
int n;
char ch;
struct ns *head,*p;
scanf("%d",&n);
head=scan(n);
while(scanf("%c",&ch)!=EOF)
{
if(ch=='O')
{o(head->next,1);break;}
if(ch=='A')
{
p=malloc(sizeof(struct ns));
p->next=NULL;
scanf("%s%d",p->name,&p->m);
a(head,p);
}
if(ch=='Q')
q(head);
if(ch=='C')
c(head);
if(ch=='S')
s(head);
}
return 0;
}
0 0
- 金牌、银牌、铜牌(C语言)
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- sdut2057金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌 银牌 铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌
- 金牌、银牌、铜牌--链表
- 2057-->金牌,银牌,铜牌
- SDUT OJ 金牌、银牌、铜牌
- 金牌、银牌、铜牌 (sdut oj)
- 学历是铜牌,能力是银牌,人脉是金牌,思维是王牌(感触很深)
- 学历是铜牌,能力是银牌,人脉是金牌,思维是王牌(感触很深)
- 学历是铜牌,能力是银牌,人脉是金牌,思维是王牌(感触很深)
- 欢迎使用CSDN-markdown编辑器
- 网站页面导入css,图片等文件的相对路径和绝对路径问题
- LightOJ - 1198 Karate Competition 【贪心】
- Guava中针对集合的 filter和过滤功能
- Python 自学开始(一,基础)
- 金牌、银牌、铜牌(C语言)
- POJ-2377 Bad Cowtractors (并查集+sort排序)
- axis2耗时问题,定时任务注入问题
- 5-14 大炮打蚊子 (15分)
- 开启博客之路
- 【Light-oj】-Integer Divisibility(同余定理)
- 浅析HTTP协议
- lightoj 1198Karate Competition(田忌赛马变形)
- linux C笔记5——Shell编程之函数