![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++程序设计 基础、编程抽象与算法策略
Claraaa_
这个作者很懒,什么都没留下…
展开
-
C++ 动态分配的strcyp函数
#include <iostream>using namespace std;//count length of char arrayint strlen(char* str) { int i = 0; while (*str++ != '\0') { i++; } return i;}// required copy string functionchar* copyCString(char* str) { int size = strlen(str); cha原创 2021-04-04 01:25:39 · 162 阅读 · 0 评论 -
汉诺塔移动次数 递归 C++
#include <iostream>using namespace std;void moveonetower(char start, char finish, int& count) { cout << start << "->" << finish << endl; }void movetower(int n, char start, char finish, char tmp, int& count) {原创 2021-03-18 15:10:24 · 436 阅读 · 0 评论 -
c++递归实现字符串倒序
#include <iostream>#include <string>using namespace std;string reverse(string& str) { if (str.length() <= 1) return str; else { string sub = str.substr(1, str.length() - 2); return str[str.length() - 1] + reverse(sub) + str[0];原创 2021-03-14 16:45:52 · 607 阅读 · 0 评论 -
c++递归 求一个整数的各个数字之和
int digitsum(int n) { if (n < 10) return n; else return (n % 10) + digitsum(n / 10);}原创 2021-03-14 13:35:48 · 501 阅读 · 0 评论 -
C++最大公约数 欧几里得算法
#include <iostream>using namespace std;int gcd(int x, int y) { if (x % y == 0) return y; else { return gcd(y, x % y); }}原创 2021-03-14 13:30:42 · 279 阅读 · 0 评论 -
C++ vector 读取一组数并求平均值和标准差
#include <iostream>#include <vector>#include <string>using namespace std;double mean(vector <double>& data);double stddev(vector <double>& data);int main() { double v; vector <double> data; cout <&l原创 2021-03-10 14:32:56 · 1568 阅读 · 2 评论 -
C++程序设计 基础、编程抽象与算法策略 第三章习题
#include <iostream>#include <string>using namespace std;bool endWith(string str, string suffix) { int a = str.length(); int b = suffix.length(); if (a < b) return false; for (int i = 0; i < b; i++) { if (str[a - i - 1] != suf...原创 2021-02-27 18:01:22 · 208 阅读 · 0 评论 -
C++程序设计 基础、编程抽象与算法策略 第二章习题
#include <iostream>using namespace std;int roundToNearstInt(double x) { int y; if (x >= 0) { y = x + 0.5; } else { y = x - 0.5; } return y;}int main() { double x; cout << "Enter the number: "; cin >> x; int y = ro...原创 2021-02-23 13:05:13 · 187 阅读 · 0 评论 -
C++程序设计 基础、编程抽象与算法策略 第一章习题
C++程序设计 基础、编程抽象与算法策略 第一章习题5.#include <iostream>using namespace std;const int SENTINEL = 0;int main(){ cout << "This program fins the largest interger in a list." << endl; cout << "Use " << SENTINEL << " to原创 2021-02-13 18:09:12 · 340 阅读 · 1 评论