![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
codewars挑战记录
qq_41825194
这个作者很懒,什么都没留下…
展开
-
C++ Beeramid 啤酒金字塔
问题是:给定钱数,和啤酒单价格,可以摆几层啤酒金字塔,规律是每一层从头层开始数量为层数的平方数;解法一:#include <iostream>#include <cmath>using namespace std;int beeramid(int bonus, double price){ if (bonus < price) return 0; auto count = (bonus / price); int i = 0; while ((原创 2021-09-19 20:54:07 · 183 阅读 · 0 评论 -
C++ RGB To Hex Conversion(RGB转换16进制)(No.11)
要求:rgb(255, 255, 255) # returns FFFFFFrgb(255, 255, 300) # returns FFFFFFrgb(0,0,0) # returns 000000rgb(148, 0, 211) # returns 9400D3解法一:#include <iostream>#include <string>#include <sstream>#include <cctype>using原创 2021-09-13 22:15:02 · 1077 阅读 · 0 评论 -
C++ Tribonacci Sequence(前三个数之和)(No.10)
要求:返回类似斐波那契数列数列的数组。只是元素为前三个数之和解法一:#include <iostream>#include <vector>using namespace std;std::vector<int> tribonacci(std::vector<int> signature, int n) { vector<int> result; if (n <= signature.size()) { f原创 2021-09-02 21:47:56 · 142 阅读 · 0 评论 -
C++ Bouncing Balls(妈妈会看到球多少次)(No.9)
要求: 一个孩子正在一座高楼的 n 层玩球。该楼层的高度h是已知的。他把球扔出窗外。球反弹(例如)到其高度的三分之二(反弹 0.66)。他的母亲从离地面 1.5 米的窗户向外望去。妈妈会看到球在她的窗前经过多少次(包括它掉落和弹跳的时候)?解法一:#include <iostream>#include <cmath>using namespace std;class Bouncingball{public: static int boun...原创 2021-09-01 21:51:20 · 160 阅读 · 0 评论 -
C++ Moving Zeros To The End(将数字0移动到后边而不改变元素的相对位置)(No.8)
要求:move_zeros({1, 0, 1, 2, 0, 1, 3}) // returns {1, 1, 2, 1, 3, 0, 0}解法一:#include <iostream>#include <vector>#include <algorithm>using namespace std;std::vector<int> move_zeroes(const std::vector<int>& input.原创 2021-08-31 21:45:41 · 177 阅读 · 0 评论 -
C++ Number of trailing zeros of N!(计算尾随零数)(No.7)
要求:Exampleszeros(6) = 1# 6! = 1 * 2 * 3 * 4 * 5 * 6 = 720 --> 1 trailing zerozeros(12) = 2# 12! = 479001600 --> 2 trailing zeros解法一:#include <iostream>#include <cmath>using namespace std;long zeros(long n) { double kp.原创 2021-08-30 21:25:54 · 247 阅读 · 0 评论 -
C++ Stop gninnipS My sdroW!(字符数大于五的翻转)(No.6)
要求:Examples:spinWords("Hey fellow warriors") => "Hey wollef sroirraw" spinWords("This is a test") => "This is a test" spinWords("This is another test") => "This is rehtona test"Write a function that takes in a string of one or more words原创 2021-08-28 21:52:59 · 211 阅读 · 0 评论 -
C++ Convert string to camel case(No.5)
Examples"the-stealth-warrior" gets converted to "theStealthWarrior""The_Stealth_Warrior" gets converted to "TheStealthWarrior"解法一:#include <string>std::string to_camel_case(std::string text) { // TODO: Your code goes here! int l = text.s.原创 2021-08-28 21:10:10 · 150 阅读 · 0 评论 -
C++ Printer Errors (No.4)
class Printer{public: static std::string printerError(const std::string &s);};std::string Printer::printerError(const std::string& s) { vector<string> my_vec; int l = s.size(); for (int i = 0; i < l; i++) { ...原创 2021-08-25 21:31:35 · 128 阅读 · 0 评论 -
C++ 任意位整数提取数字,Playing with digits(No.3)
如上规律,提供初始幂次,返回倍数,如1、2、51.class DigPow{public: static int digPow(int n, int p);};int DigPow::digPow(int n, int p) { vector<int> my_array; int temp = n; int yushu; while (n >= 10) { yushu = n % 10; n = n / 10; my_array.push_bac...原创 2021-08-24 20:19:14 · 147 阅读 · 0 评论 -
C++拆分字符串,两两输出(No.2)
Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').将字符串拆分为两个字符为一对,不足两个字符的,补齐一个原创 2021-08-20 21:54:12 · 354 阅读 · 0 评论 -
C++ 字符串string 转换成数字格式(No.1)
sstream头文件的作用:常用于字符串类型与数值的相互转换存在一字符串,内容为数字,相互之间以空格隔开,如何取出其中的最值#include <sstream>#include <vector>using namespace std;string highAndLow(const string& numbers){ int num; stringstream iss(numbers); vector<int> nums; w转载 2021-08-17 23:15:34 · 597 阅读 · 0 评论