#include <stdio.h>
#include <stdlib.h>
struct ListNode {
int data;
struct ListNode *next;
};
struct ListNode *createlist(); /*裁判实现,细节不表*/
struct ListNode *reverse( struct ListNode *head );
void printlist( struct ListNode *head )
{
struct ListNode *p = head;
while (p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
int main()
{
struct ListNode *head;
head = createlist();
head = reverse(head);
printlist(head);
return 0;
}
/* 你的代码将被嵌在这里 */
struct ListNode *reverse( struct ListNode *head ){
struct ListNode *begin,*mid,*end;
if(head==NULL)
return NULL;
begin=NULL,mid=head,end=head->next;
while(1){
mid->next=begin;
if(end==NULL)
break;
begin=mid;
mid=end;
end=end->next;
}
return mid;
}
1
3
Zhangsan 20
Lisi 21
Wangwu 20
#include<stdio.h>
struct stu {
char name[100];
int a;
};
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int i;
struct stu s[n];
for(i=0;i<n;i++)
scanf("%s %d",s[i].name,&s[i].a);
for(i=n-1;i>=0;i--)
printf("%s %d\n",s[i].name,s[i].a);
}
}