1、行程编码压缩算法
1 #include<stdio.h> 2 #include <string.h> 3 #define N 100 4 5 int main() 6 { 7 char s[N] = "", t[N] = "", ch; 8 gets(s); 9 10 int count = 0, index = 0; 11 for(int i=0; s[i]; ++i) 12 { 13 if(!count) 14 ch = s[i]; 15 count++; 16 if(ch!=s[i+1] || count==9){ 17 t[index++] = count+'0'; 18 t[index++] = ch; 19 count=0; 20 } 21 } 22 printf("%s",t); 23 return 0; 24 }
2、创建与遍历职工链表
1 #include <stdio.h> 2 #include <malloc.h> 3 #include <string.h> 4 #define N 100 5 6 typedef struct node EMPLOYEE,*LIST; 7 struct node{ 8 int num; 9 LIST next; 10 }; 11 12 void Insert(LIST head,int num) 13 { 14 LIST p = head, s; 15 s = (LIST)malloc( sizeof(EMPLOYEE) ); 16 s->num = num; //给p赋值 17 18 while(p->next != NULL && s->num >= p->next->num) 19 p = p->next; 20 //连接 21 s->next = p->next; //若s最大, p->next=NULL 22 p->next = s; 23 } 24 25 LIST Create() 26 { 27 //创建头结点 28 LIST head = (LIST)malloc(sizeof (EMPLOYEE)); 29 head->next = NULL; 30 31 int n,num; 32 scanf("%d",&n); 33 //插入n个职工号 34 while(n--) 35 { 36 scanf("%d",&num); 37 Insert(head,num); 38 } 39 return head; 40 } 41 42 void Print(LIST head) 43 { 44 LIST p = head; 45 while(p->next != NULL) 46 { 47 p = p->next; 48 printf("%d ",p->num); 49 } 50 } 51 52 int main() 53 { 54 LIST head = Create(); 55 Print(head); 56 return 0; 57 }
3、毕业设计论文打印