1、1、将一个字符串逆序 2、将一个链表逆序 3、计算一个字节里(byte)里面有多少bit被置1 4、搜索给定的字节(byte) 5、在一个字符串中找到也许的最长的子字符串 6、字符串转换为整数 7、整数转换为字符串 style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="break-word"1、char *strconv(char *p) { int i,length; char temp; length = strlen(p);
2、 for(i = 0;i < length/2;i++) { temp = *(p + i); *(p + i) = *(p + length - 1 - i); *(p +length - 1 - i) = temp; } return p; } int main() { char src[100]; char *p; scanf("%s",src); p = strconv(src);
3、 printf("%s\n",p); return 0; } style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="break-word"3、int cal(int data) //calculation the number of bit in one byte { int a; int count = 0; a = data % 100; while (a != 0) {
4、 count += a % 2; a /= 2; } return count; } int main() { int d,count; scanf("%d",&d); count = cal(d); printf("%d of one\n",count); return 0; } style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="b
5、reak-word"4、#include
6、 { if(count > max) { max = count; record[j] = '\0'; strcpy(recordmax,record); } count = 0; j = 0; } else {
7、 record[j] = *(p + i); count ++; j ++; } if(*(p + i) == '\0') break; } printf("%s\n",recordmax); } int main() { char str[]="zeng weidsfdsaf langd hah"; pr
8、intf("%s\n",str);
findmax(str);
return 0;
}
style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="break-word"#include
9、 }SHOP; SHOP *buildlink() //创建链表 { char goods[100]; SHOP *head,*p,*h; p = (SHOP *)malloc(sizeof(SHOP)); head = p; head->next = NULL; printf("Input three goods:"); for(int i = 0;i < 3;i++) { scanf("%s",goods);
10、 p = (SHOP *)malloc(sizeof(SHOP)); strcpy(p->goods,goods); p->next = NULL; if(head->next == NULL) { head->next = p; h = p; } else { h->next = p; h = h->n
11、ext; } } return head; } void showlink(SHOP *head) //显示链表 { SHOP *p; p = head->next; while(p != NULL) { printf("%s ",p->goods); p = p->next; } printf("\n"); } SHOP *revlink(SHOP *head)
12、//反转链表 { SHOP *p,*newp; p = head->next; head->next = NULL; while(p != NULL) { newp = p; p = p->next; newp->next = head->next; head->next = newp; } return head; } int delnode(SHOP *head,char
13、str) { //delete success return 1,else return 0 SHOP *q,*p = head; while(p->next != NULL) { q = p; p = p->next; if(!strcmp(str,p->goods)) { q->next = p->next; free(p); //p
14、 q->next; return 1; } } return 0; } int main() { SHOP *head; SHOP *newhead; head = buildlink(); showlink(head); newhead = revlink(head); showlink(newhead); showlink(head);
15、 printf("Delete a node:"); char str[50]; scanf("%s",str); int i; i = delnode(head,str); showlink(head); if(i == 1) printf("Delete successful!\n"); return 0; } style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="
16、break-word"#include
17、of(SHOP)); head = p; head->next = NULL; printf("Input three goods:"); for(int i = 0;i < 3;i++) { scanf("%s",goods); p = (SHOP *)malloc(sizeof(SHOP)); strcpy(p->goods,goods); p->next = NULL; if(head->next == NUL
18、L) { head->next = p; h = p; } else { h->next = p; h = h->next; } } return head; } void showlink(SHOP *head) //显示链表 { SHOP *p; p = head->next;
19、 while(p != NULL) { printf("%s ",p->goods); p = p->next; } printf("\n"); } SHOP *revlink(SHOP *head) //反转链表 { SHOP *p,*newp; p = head->next; head->next = NULL; while(p != NULL) { newp = p;
20、 p = p->next; newp->next = head->next; head->next = newp; } return head; } int delnode(SHOP *head,char *str) { //delete success return 1,else return 0 SHOP *q,*p = head; while(p->next != NULL) { q =
21、p; p = p->next; if(!strcmp(str,p->goods)) { q->next = p->next; free(p); //p = q->next; return 1; } } return 0; } int main() { SHOP *head; S
22、HOP *newhead; head = buildlink(); showlink(head); newhead = revlink(head); showlink(newhead); showlink(head); printf("Delete a node:"); char str[50]; scanf("%s",str); int i; i = delnode(head,str); showlink(head)
23、 if(i == 1) printf("Delete successful!\n"); return 0; } style="MARGIN: 0px; COLOR: rgb(102,102,102); LINE-HEIGHT: 150%" wrap="break-word"#include "stdio.h" #include "stdlib.h" int myAtoi(char *s); void main() { int i; char *s=(cha
24、r *)malloc(10*sizeof(char)); if (s==NULL) { printf("fail to malloc s\n"); return; } while(1) { scanf("%s",s); if ((*s)=='q') { break; } i = myAtoi(s); printf("%d\n",i); } } i
25、nt myAtoi(char *s) { int i=0; int flag=0; if (s==NULL)return 0; if (*s=='+'||*s=='-') { if (*s=='-') { flag=1; } s++; } while(*s!='\0' && *s>='0' && *s<='9') { i=(int)(*s)-'0'+i*10; s++; } if (flag)i=-i; return i; }






