| ||||||||||
| 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 | |||||||||
用链表解决的,汗,16MS 1090B的代码,好像太复杂了点,欢迎大牛改进#include<stdio.h>
#include<stdlib.h>
typedef struct LNode{
char data[500];
int count,flag;//关键字和开关
struct LNode *next;
}LNode,*LinkList;
int Sort(char ch[],int m)//求逆序数
{
int i,j,count=0;
for(i=0;i<m;i++)
{
for(j=i+1;j<m;j++)
{
if(ch[i]>ch[j])count++;
}
}
return count;
}
void bubble(int a[],int n)//对数组冒泡排序
{
int i,j;
for(i=n-1;i>0;i--)
{
for(j=0;j<i;j++)
{
if(a[j]>a[j+1])
{
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main()
{
int m,n,cou[10000];
LNode *p,*p1;
LinkList head;
int i,j;
head=(LinkList)malloc(sizeof(LNode));
p1=(LNode *)malloc(sizeof(LNode));
p=head;
while(scanf("%d%d",&m,&n)!=EOF)
{
getchar();
for(j=0;j<n;j++)
{
gets(p1->data);
cou[j]=Sort(p1->data,m);
p1->flag=0;
p1->count=cou[j];
p->next=p1;
p=p1;
p1=(LNode *)malloc(sizeof(LNode));
}
bubble(cou,n);
p->next=NULL;
for(i=0;i<n;i++)
{
p=head->next;
while(p)
{
if(p->count==cou[i]&&p->flag==0)
{
printf("%s\n",p->data);
p->flag=1;
break;
}
p=p->next;
}
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator