数字的逆序输出
记住:
n = n * 10 + number % 10;
number = number / 10;
#include <stdio.h>
# include <math.h>
unsigned int reverse( unsigned int number );
int main()
{
unsigned int n;
scanf("%u", &n);
printf("%u\n", reverse(n));
return 0;
}
/* 请在这里填写答案 */
unsigned int reverse( unsigned int number ){
int n=0;
while(number){
n=n*10+number%10;
number/=10;
}
return n;
}
链表逆置输出
记住:
#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;
}
编程l----链表逆置
记住:输入的时候>>>>>>for( i=0;i < n;i++)
输出的时候>>>>>>for( i = n - 1; i > = 0; i--)
#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);
}
}