以下是引用zghnxzdcx在2010-10-24 19:22:28的发言:
话不要说的那么直白
确实很直白 但是确实是事实
话不要说的那么直白
到底是“出来混迟早要还”还是“杀人放火金腰带”?
#include<stdio.h> main(void) { int i,j,k; char *p1="abcbefghi jklmnopqrstuvwyz"; char *p2="ngzqtcobmuhelkpdawxfylvrsj"; char c; printf("输入需要加密的字符串:\n"); while ((c=getchar())) for(i=0 ; i< 26; i++) if(c == *(p1+i))printf("%c" , *(p2+i)); return 0; }解密程序
#include<stdio.h> main(void) { int i,j,k; char *p2="abcbefghi jklmnopqrstuvwyz"; char *p1="ngzqtcobmuhelkpdawxfylvrsj"; char c; printf("输入需要解密的字符串:\n"); while ((c=getchar())) for(i=0 ; i< 26; i++) if(c == *(p1+i))printf("%c" , *(p2+i)); return 0; }
#include<stdio.h> int binsearch(int , int[], int); main(void) { int c,m; int i,j,k; int num[10]; printf("输入10个数的有序数列:"); for(i =0; i<10; i++) {scanf("%d" , &c); num[i] = c; } printf("输入要查找的的数字:"); scanf("%d" , &m); // printf("%d\n" ,binsearch(m,num,10)); if(binsearch(m,num,10) >= 0) printf("FOUND!\n"); else printf("NOT FOUND!\n"); return ; } int binsearch(int x, int v[], int n)/*折半查找法函数*/ { int low,high,mid; low =0; high = n-1; while(low < high) { mid =(low + high)/2; if(x < v[mid]) high = mid- 1; else if (x > v[mid]) low =mid -1; else return mid;/*找到了匹配的的值*/ } return -1;/*没有匹配的的值*/ }第二个题目的答案,程序基本能行,凑活着看吧,能运行处结果!
#include <stdio.h> void qsort(int[], int, int); void swap(int[], int, int); void main(void) { int i, j,n; int num[10]; printf("输入任意10个数:"); for(i = 0; i < 10; i++) {scanf("%d", &n); num[i]= n; } qsort(num,0,9); for(j = 0; j<10;j++) printf("%d " , num[j]); } void qsort(int v[], int left, int right) { int i, last; if (left >= right) return; swap(v, left, (left + right)/2); last=left; for (i = left+1; i <= right; i++) if (v[i] < v[left]) swap(v, ++last, i); swap(v, left, last); qsort(v, left, last-1); qsort(v, last+1, right); } void swap(int s[], int i, int j) { int temp; temp = s[i]; s[i] = s[j]; s[j] = temp; }第四题的答案,楼主慢慢看看吧
/*3.编程: 建立一个链表,长度为5。从键盘输入每个结点的内容,每个结点包括:学号、姓名、性别、年龄。 输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则在屏幕上显示该结点,然后将该结点删除。 否则显示“NOT FIND” */ #include<stdio.h> #include<malloc.h> #include<string.h> typedef struct node { int num; char name[3]; char sex; int age; struct node *next; }node; main(void) { int i,j,k; int st_num,st_age; char st_sex,st_name[3]; node *imf[5]; for(i = 0; i<5; i++) { imf[i]=(node *)malloc(sizeof(node)); printf("【输入信息】\n\n"); printf("输入学号:"); scanf("%d" ,&st_num); printf("输入姓名:"); scanf("%s" ,&st_name); printf("输入性别:"); scanf("%s" ,&st_sex); printf("输入年龄:"); scanf("%d" , &st_age); imf[i]->num = st_num; strcpy(imf[i]->name,st_name); imf[i]->sex = st_sex; imf[i]->age = st_age; imf[i]->next = NULL; system("cls"); } printf("%d\n" ,imf[4]->age); /*建立单链表, 由于我知道了链的长度才这样手工建链, 一般会有个建链函数*/ node *head; head = imf[0]; imf[0]->next = imf[1]; imf[1]->next = imf[2]; imf[2]->next = imf[3]; imf[3]->next = imf[4]; imf[4]->next = NULL; /*年龄查找*/ node *p; int s_age,s_i; printf("输入年龄:") ; scanf("%d" ,&s_age) ; for(j = 0; j<5; j++) if(imf[j]->age == s_age){s_i=j;break;} else if(imf[j]->next == NULL) {printf("NOT FOUND!\n");return;} printf("FOUND\n学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n",imf[s_i]->num,imf[s_i]->name,imf[s_i]->sex,imf[s_i]->age); /*删除结点*/ if(s_i ==0)head = imf[1];/*头结点时*/ else if(s_i == 4)imf[3]->next = NULL;/*尾结点时*/ else imf[s_i-1]->next = imf[s_i+1];/*中间节点时*/ printf("结点删除!\n"); }尽管已经结贴,这是第三道的程序。