摘要:
用算法实现将一个输入的数字颠倒(输入12345->54321),要求不调用任何系统函数,也不能将输入的数字转换为字符串作为中间过渡 1 //用算法实现将一个输入的数字颠倒(输入12345->54321),要求不调用任何系统函数,也不能将输入的数字转换为字符串作为中间过渡 2 #include "stdafx.h" 3 4 long reverse(long num) 5 { 6 long x=0; 7 while(num) 8 { 9 x=x*10;10 x=x+num%10;11 ... 阅读全文
摘要:
1 // 删除一个字符串中的子串 2 3 #include "stdafx.h" 4 #include 5 6 int delete_substr(char *str1,char *str2) 7 { 8 int pos=0,k=0,staic=0,n; 9 int str1_len=strlen(str1);10 int str2_len=strlen(str2);11 for(int i=0;i<str1_len;i++)12 {13 for(int j=0;j<str2_len;j++)14 {15 ... 阅读全文
摘要:
不调用任何系统函数,实现一个字符串查找子串的函数,如果包含字串,则返回该字符串的位置值,如果不包含,则返回-1 1 //不调用任何系统函数,实现一个字符串查找子串的函数,如果包含字串,则返回该字符串的位置值,如果不包含,则返回-1 2 #include "stdafx.h" 3 #include 4 5 //方法1 6 int search_max_substr1(const char *str1,const char *str2)//在str1中查找子串str2 7 { 8 int pos=0,k=0,staic=0; 9 int str1_len=strlen(str1 阅读全文
摘要:
1 #include "stdafx.h" 2 #include 3 # define MAX 100 4 5 void main() //输出100以为的质数 6 { 7 int i,j; 8 for(i=1;i<=MAX;i++) 9 {10 for(j=2;j<=i;j++)11 {12 if(i%j==0)13 break;14 }15 if(i==j)16 printf("%d\t",i);17 }18... 阅读全文
摘要:
1 #include "stdafx.h" 2 #include 3 4 bool Is_palindromic(int num) //判断一个数是不是回文数 5 { 6 int pal=0; 7 int number=num; 8 while(num) 9 {10 pal*=10;11 pal+=num%10;12 num/=10;13 }14 return pal==number;15 }16 17 void main()18 {19 int n,m;20 printf("... 阅读全文
摘要:
1 #include "stdafx.h" 2 #include 3 #include 4 #define MAX 100 5 6 //在字符串str1和str2中查找最大的公共子串maxsubstr 7 void findmaxsubstr(const char *str1,const char *str2,char *maxsubstr) 8 { 9 int maxlen=0,maxpos=-1;10 int k;11 for(int i=0;imaxlen)22 {23 ... 阅读全文