#include <stdio.h>; void swap(int *a, int *b); int main (void) { int number[10]; int i, j;//循环变量 while (scanf("%d", &number[0]) != EOF) { for (i = 1 ; i < 10 ; i++) scanf("%d", &number[i]); for (i = 0 ; i < 9 ; i++) { for (j = 0 ; j <= 8 - i ; j++) { if (number[j] > number[j+1]) swap(&number[j], &number[j+1]); } } for (i = 0 ; i < 10 ; i++) { if (i != 0) printf("->"); printf("%d", number[i]); } putchar('\n'); } return 0; } void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; return; }
第二题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <stdio.h>; int main (void) { long number; char currentByte; int count; while (scanf("%ld", &number) != EOF) { for (count = 7 ; count >= 0 ; count--) { currentByte = (((0xf << (count * 4)) & number) >> (count * 4)) & 0xf; printf("%hd(%c) ", currentByte, currentByte); } putchar('\n'); } return 0; }
#include <stdio.h>; void swap(int *a, int *b); void moveArray(int a[], int n, int m);//轮移数组,其中n为总个数,m为轮移次数 int main (void) { int number[22]; int individualNumber, middleNumber; int i;//循环变量 while ((scanf("%d", &individualNumber), individualNumber) != 0) { scanf("%d", &middleNumber); for (i = 0 ; i < individualNumber ; i++) scanf("%d", &number[i]); moveArray(number, individualNumber, middleNumber); for (i = 0 ; i < individualNumber ; i++) { if (i != 0) putchar(' '); printf("%d", number[i]); } putchar('\n'); } return 0; } void moveArray(int a[], int n, int m) { if (m == 0) { return; } else { int temp, count; temp = a[0]; for (count = 0 ; count < n - 1 ; count++) a[count] = a[count+1]; a[n-1] = temp; moveArray(a, n, --m); } } void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; return; }
#include<stdio.h> #include<string.h> void swap(int *score_a, int *score_b, char *name_a, char *name_b); int main (void) { int number, count; while (scanf("%d", &number) != EOF) { putchar('\n'); int scores[number]; char names[number][81]; for (count = 0 ; count < number ; ++count) scanf("%s%d", names[count], &scores[count]); int i, j; for (i = 0 ; i < number ; ++i) for (j = i ; j < number ; ++j) if (scores[i] < scores[j]) swap(&scores[i], &scores[j], &names[i][0], &names[j][0]); for (count = 0 ; count < number ; ++count) printf("%s %d\n", names[count], scores[count]); putchar('\n'); } return 0; }
#include <stdio.h> int main (void) { int number,count; int current; int i; while (scanf("%d", &number) != EOF) { int people[10000]; for (i = 0 ; i < number ; ++i) people[i] = 1; count = number; current = 0; i = 0; while (count > 1) { if (i >= number) i = 0; if (people[i] == 1) current += 1; if (count == 1) break; if (current == 3) { people[i] = 0; count -= 1; current = 0; } i++; } for (i = 0 ; i < number ; ++i) if (people[i] == 1) { printf("%d\n", i + 1); break; } } return 0; }
#include <stdio.h> #define Swap(x,y) {x = x + y; y = x - y; x = x - y;}
int main (void) { int a, b; int count = 0; while (scanf("%d%d", &a, &b) != EOF) { if (count) putchar('\n'); count += 1; printf("Case %d:\n", count); printf("Before Swap:a=%d b=%d\n", a, b); Swap(a,b); printf("After Swap:a=%d b=%d\n", a, b);
#include <stdio.h> int main (void) { int sequence[20]; int number; int count; int i, j; int temp; while (scanf("%d", &number), number != 0) { for (count = 0 ; count < number ; ++count) scanf("%d", &sequence[count]); for (i = 0 ; i < number ; ++i) for (j = i ; j < number ; ++j) if (sequence[i] > sequence[j]) { temp = sequence[i]; sequence[i] = sequence[j]; sequence[j] = temp; } for (count = 0 ; count < number ; ++count) { if (count) putchar(' '); printf("%d", sequence[count]); } putchar('\n'); } return 0; }