hdu 2020 我ACM的处女题 代码超有意思,记念~~~
http://acm.hdu.edu.cn/showproblem.php?pid=2020
题意:输入n(n<=100)个整数,按照绝对值从大到小排序后输出。题目保证对于每一个测试实例,所有的数的绝对值都不相等。
思路:先把所有的数据一组一组全部读入,然后再一组一组的排序,最后一组一组的输出,都是基于链表实现的。
呵呵,这是大一的代码,在hdu上的第一次提交的,当时还有printf("input what you want");这些搞笑的东西。现在改改控制一个输入输出,居然ac了。

#include<stdio.h> #include<stdlib.h> struct date { int data; char sign; struct date *next; }; int main() { char k; int i=0,a[105],j,t,f; struct date *p,*head,*h,*q,*y; if ((p=(struct date *)malloc(sizeof(struct date)))==NULL) { printf("error!!!\n");exit(0); } else head=p; scanf("%d",&a[i]); while ( a[i] ) { for( j=0;j<a[i];j++ ) { scanf("%d",&p->data); if ( p->data<0 ) { p->sign='-'; p->data=p->data*(-1); } else p->sign=' '; if((p->next=(struct date *)malloc(sizeof(struct date)))==NULL) { printf("error!!!\n");exit(0); } else p=p->next; } i++; scanf("%d",&a[i]); } p->next=NULL; p=head; h=head; i=0; while ( a[i] ) { for ( j=0,q=p=h;j<a[i]-1;j++ ) { for ( t=0;t<a[i]-1;t++ ) { if ( p->next!=NULL&&p->data<p->next->data ) { f=p->data; p->data=p->next->data; p->next->data=f; k=p->sign; p->sign=p->next->sign; p->next->sign=k; p=p->next; } else p=p->next; } y=p->next;p=q; } i++;h=y; } p=head; h=head; i=0; while ( a[i] ) { int flag = 0; for ( j=0;j<a[i];j++ ) { if(flag)printf(" "); if ( p->sign=='-') printf("%d",p->data*(-1)); else printf("%d",p->data); flag = 1; p=p->next; } // if ( a[i+1]==0 ) printf("%d",a[i+1]); i++; printf("\n"); } return 0; }