摘要: 在编程中常会碰到,在某一个集合中,选集合中的几个数据进行计算。决定写个类似伪代码的代码,方便日后编程。int index=0;保存结果的集合;void fun(集合,集合长度,要选取的长度){ if(集合长度 < 要选取的长度) return ; if(要选取的长度<=0) {自己想要实现的功能模块} for(int i=0;i<集合长度;i++) { 保存结果的集合[index++]=集合[i]; fun(集合+i+1,集合长度-i-1,要选取的长度-1); index--; }} 阅读全文
posted @ 2013-05-02 11:24 浪浪辛 阅读(183) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 #include<conio.h> 3 int fun(int m,int n) 4 { 5 if(m==n)return 1; 6 if(n==1)return m; 7 return fun(m-1,n)+fun(m-1,n-1); 8 } 9 int main()10 {11 printf("%d\n",fun(7,3));12 getch();13 return 0;14 } 阅读全文
posted @ 2013-05-02 11:04 浪浪辛 阅读(234) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 #include<conio.h> 3 int result[100]; 4 5 void split(int n, int k, int c) 6 { 7 if (k == 0) return; 8 if (n == k) 9 {10 result[c]=k;11 for (int i = 0; i <=c; i++)12 printf("%d ",result[i]);13 printf("\n"); 14 if (k == 1)... 阅读全文
posted @ 2013-05-02 11:01 浪浪辛 阅读(194) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 #include<conio.h> 3 char pStr[20]="abcd"; 4 void swap(char *a,char *b) 5 { 6 char temp = *a; 7 *a = *b; 8 *b = temp; 9 }10 void comp(char *pBegin)11 {12 if(!*pBegin)puts(pStr);13 char *p=pBegin;14 for(;*p;p++)15 {16 swap(p,pBegin);17 ... 阅读全文
posted @ 2013-05-02 10:58 浪浪辛 阅读(230) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 4 char s[50]; 5 int index=0; 6 void reSort(char *pArray, int remainNum, int printLen) 7 { 8 if (remainNum < printLen)return; 9 if (printLen <= 0)10 {11 for(int i=0;i<index;i++)12 putchar(s[i]);13 putchar('\n');14 ... 阅读全文
posted @ 2013-05-02 10:55 浪浪辛 阅读(209) 评论(0) 推荐(0)
摘要: 整数转换为字符串:char *itoa( int value, char *string,int radix);小数转换为字符串:sprintf(串, 格式控制符列, 数据);字符串转小数:double atof(const char *nptr);字符串转整数:int atoi(const char *nptr);测试代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int a=2013420; 6 float b=2.054f; 7 double c=5.24; 8 char s... 阅读全文
posted @ 2013-05-01 01:29 浪浪辛 阅读(301) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 int main() 3 { 4 /*float型数据测试*/ 5 printf("13.37499四舍五入后变为%.2f\n",13.37499f); 6 printf("13.37500四舍五入后变为%.2f\n\n",13.37500f); 7 /*double型数据测试*/ 8 printf("13.4四舍五入后变为%.0lf\n",13.4); 9 printf("13.5四舍五入后变为%.0lf\n",13.5);10 getchar();11 r 阅读全文
posted @ 2013-05-01 00:45 浪浪辛 阅读(840) 评论(0) 推荐(0)
摘要: 30年的改革开放,给中国带来了翻天覆地的变化。2011全年中国手机产量约为11.72亿部。手机已经成为百姓的基本日用品! 给手机选个好听又好记的号码可能是许多人的心愿。但号源有限,只能辅以有偿选号的方法了。 这个程序的目的就是:根据给定的手机尾号(4位),按照一定的规则来打分。其规则如下: 1. 如果出现连号,不管升序还是降序,都加5分。例如:5678,4321都满足加分标准。 2. 前三个数字相同,或后三个数字相同,都加3分。例如:4888,6665,7777都满足加分的标准。注意:7777因为满足这条标准两次,所以这条规则给它加了6分。 3. 符合AABB或者ABAB模式的加1分。例如:2 阅读全文
posted @ 2013-05-01 00:18 浪浪辛 阅读(391) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 char a[1500000]={0}; 3 int main() 4 { 5 int temp,n=1, i; 6 for(i=2;i<1500000;i++) 7 for(temp=2*i;temp<1500000;temp+=i) 8 a[temp]=1; 9 for(i=2;i<=100002;i++)10 while(a[n+=2]);11 printf("%d\n",n);12 getchar();13 return 0;14 } 阅读全文
posted @ 2013-04-26 19:25 浪浪辛 阅读(353) 评论(0) 推荐(0)
摘要: 1 #include <stdio.h> 2 3 int fun(int m,int n) 4 { 5 if(m%n==0) 6 return n; 7 return fun(n,m%n); 8 } 9 10 int main(void)11 {12 printf("%d\n",fun(18,14));13 getchar();14 return 0;15 } 阅读全文
posted @ 2013-04-26 19:23 浪浪辛 阅读(178) 评论(0) 推荐(0)