|
|
发表于 2019-8-13 00:18:51
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_REMIND 50
- #define MSG_LEN 60
- int main(void)
- {
- char reminders[MAX_REMIND][MSG_LEN + 3] ;
- char day_str[3] , msg_str[MSG_LEN + 1] ;
- int day[MAX_REMIND]={0} , i , j = 0 , num_remind = 0 , ch , len = 0 ;
- int tx ;
- char * p[MAX_REMIND] , * px ;
- for(;;) {
- printf("Enter the day and reminder : ") ;
- scanf("%d" , & day[j]) ;
- if(day[j] == 0) break ;
- while(day[j] > 99) day[j] /= 10 ;
- sprintf(day_str , "%2d" , day[j]) ;
- i = 0 ;
- msg_str[i] = '\0' ;
- while((ch = getchar()) != '\n') msg_str[i ++] = ch ;
- msg_str[i]= '\0' ;
- strcat(strcpy(reminders[j] , day_str) , msg_str) ;
- j ++ ;
- }
- for(i = 0 ; i < j ; i ++) {
- p[i] = reminders[i] ;
- len ++ ;
- }
- for(i = 1 ; i < len ; i ++) {
- for(j = i ; j > 0 && day[j] < day[j - 1] ; j --) {
- tx = day[j] ;
- day[j] = day[j - 1] ;
- day[j - 1] = tx ;
- px = p[j] ;
- p[j] = p[j - 1] ;
- p[j - 1] = px ;
- }
- }
- for(i = 0 ; i < len ; i ++) printf("%s\n" , p[i]) ;
- }
复制代码
你是怎么弄的,看看我这里的运行实况:
- C:\Bin>g++ -o x2 x2.c
- C:\Bin>x2
- Enter the day and reminder : 13 1234
- Enter the day and reminder : 12 1234
- Enter the day and reminder : 11 1234
- Enter the day and reminder : 1588 1234
- Enter the day and reminder : 1789 1234
- Enter the day and reminder : 19870 1234
- Enter the day and reminder : 291876 1234
- Enter the day and reminder : 5 1234
- Enter the day and reminder : 2 1234
- Enter the day and reminder : 0
- 2 1234
- 5 1234
- 11 1234
- 12 1234
- 13 1234
- 15 1234
- 17 1234
- 19 1234
- 29 1234
- C:\Bin>
复制代码 |
|