![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法与数据结构
autuan_liu
有梦想不可怕,可怕的是有了梦想而没有坚持!
展开
-
数字拆解
//特殊乘法#include <stdio.h> int main() { int a,b; while(scanf("%d%d",&a,&b) != EOF) { int buf1[20],buf2[20],size1 = 0,size2 = 0; do { buf1[size1++] = a % 10原创 2017-03-19 21:54:52 · 1211 阅读 · 0 评论 -
求阶乘的两种方法
/* * 求阶乘的 预处理法 */ #include <iostream> using namespace std; const int N = 1000;int main() { int a[N]; a[0] = 1; for (int i = 1; i < N; ++i) { a[i] = i * a[i-1]; } int n;原创 2017-03-19 21:56:18 · 2434 阅读 · 0 评论 -
最大公约数&&最小公倍数
//最大公约数-递归形式 #include <stdio.h> int gcd(int a,int b) { if(b == 0) return a; else return gcd(b,a%b); } int main() { int a,b; while(scanf("%d%d",&a,&b) != EOF) {原创 2017-03-19 21:58:14 · 425 阅读 · 0 评论 -
二分幂法求x^n
/* * 二分幂法 求x^n */#include <iostream> using std::cin; using std::cout; using std::endl;double powerf(double x, unsigned n) { double ans = 1.0; while (n != 0) { if (n % 2 == 1)原创 2017-03-19 21:59:07 · 714 阅读 · 0 评论 -
素数筛算法
/* * 素数筛算法 */ #include <iostream> using namespace std;const int N = 1000; int prime[N]; //存储素数的数组 int size = 0; //用于素数的计数 bool isPrime[N+1]; // 用于标记void init() { for (int i = 0; i < N + 1; ++i)原创 2017-03-19 21:59:39 · 366 阅读 · 0 评论 -
实现两个int 型数据交换的三种方法
/* * 实现两个int 型数据交换的三种方法 * */#include <iostream> using std::cout; using std::endl; using std::cin;//借助临时变量 void swapint1(int &a, int &b) { int temp = a; a = b; b = temp; }//借助加减法实现 void swa原创 2017-03-19 22:00:18 · 2283 阅读 · 0 评论 -
实现字符串对换的两种方法
/* * 实现字符串对换的两种方法 * */ #include <iostream> #include <string> using namespace std;void swapstr1(string &str1, string &str2) { string temp; temp = str1; str1 = str2; str2 = temp; }void s原创 2017-03-19 22:02:22 · 1524 阅读 · 0 评论 -
斐波那契数列的两种实现方法
/* * 使用数组的方式实现 斐波那契数列 * */#include <stdio.h> const int N = 1001;int main() { int fi[N]; fi[0] = 1; fi[1] = 1; for (int i = 2; i < N; ++i) { fi[i] = fi[i-1] + fi[i-2]; }原创 2017-03-19 22:04:01 · 426 阅读 · 0 评论