![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题
Salted_Sun
这个作者很懒,什么都没留下…
展开
-
【codewars-20】素数的间距
The prime numbers are not regularly spaced. For example from 2 to 3 the step is 1. From 3 to 5 the step is 2. From 7 to 11 it is 4. Between 2 and 50 we have the following pairs of 2-steps primes:3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43We will原创 2022-04-02 14:32:53 · 203 阅读 · 1 评论 -
【codewars-19】斐波那契的变种问题
Well met with Fibonacci bigger brother, AKA Tribonacci.As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won’t get原创 2022-04-02 14:08:46 · 198 阅读 · 0 评论 -
【codewars-18】弹跳球
A child is playing with a ball on the nth floor of a tall building. The height of this floor, h, is known.He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).His mother looks out of a window原创 2022-04-02 13:14:39 · 212 阅读 · 0 评论 -
【codewars-17】统计字符的出现次数
The main idea is to count all the occurring characters in a string. If you have a string like aba, then the result should be {‘a’: 2, ‘b’: 1}.What if the string is empty? Then the result should be empty object literal, {}.#include <map>#include &l原创 2022-03-29 14:43:47 · 136 阅读 · 0 评论 -
【codewars-16】根据大小写的比例转换大小写
In this Kata, you will be given a string that may have mixed uppercase and lowercase letters and your task is to convert that string to either lowercase only or uppercase only based on:make as few changes as possible.if the string contains equal number o原创 2022-03-29 14:32:17 · 131 阅读 · 0 评论 -
【codewars-15】返回去除了奇数的数组
The solution would work like the following:get_even_numbers({2,4,5,6}) => {2,4,6}朴素的解法#include <vector>#include <numeric>std::vector<int> get_even_numbers(const std::vector<int>& arr) { std::vector<int> re原创 2022-03-28 21:50:44 · 406 阅读 · 0 评论 -
【codewars-14】选择性转换大写
Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index 0 will be considered even.For example, capitalize(“abcdef”) = [‘AbCdEf’, ‘aBcDeF’]. See test cases for more examples.The input wi原创 2022-03-27 16:16:09 · 415 阅读 · 0 评论 -
【codewars-13】和为奇数还是偶数 ?
Task:Given a list of integers, determine whether the sum of its elements is odd or even.Give your answer as a string matching “odd” or “even”.If the input array is empty consider it as: [0] (array with a zero).Examples:Input: [0]Output: "even"Input原创 2022-03-27 15:43:13 · 173 阅读 · 0 评论 -
【codewars-12】Parts of a list. 分割list
Write a function partlist that gives all the ways to divide a list (an array) of at least two elements into two non-empty parts.Each two non empty parts will be in a pair (or an array for languages without tuples or a structin C - C: see Examples test Cas原创 2022-03-27 12:59:13 · 965 阅读 · 0 评论 -
【codewars-11】对多行文本做对称变换 Moves in squared strings (I)
This kata is the first of a sequence of four about “Squared Strings”.You are given a string of n lines, each substring being n characters long: For example:s = "abcd\nefgh\nijkl\nmnop"We will study some transformations of this square of strings.Vertic原创 2022-03-27 00:34:00 · 211 阅读 · 0 评论 -
【codewars-10】字符串的结尾
Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).Examples:solution('abc', 'bc') // returns truesolution('abc', 'd') // returns false要点用迭代器初始化字符串的方式截取出字符串的尾部要在str长度>e原创 2022-03-25 21:55:21 · 279 阅读 · 0 评论 -
【codewars-9】预测年龄
My grandfather always predicted how old people would get, and right before he passed away he revealed his secret!In honor of my grandfather’s memory we will write a function using his formula!Take a list of ages when each of your great-grandparent died.原创 2022-03-25 21:27:18 · 294 阅读 · 0 评论 -
【codewars-8】字符串二合一
Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters - each taken only once - coming from s1 or s2.用两个字符串中的字符组成无重复字符且升序排列的字符串Examples:a = "xyaabbbccccdefww"b = "xxxxyy原创 2022-03-25 11:47:58 · 146 阅读 · 0 评论 -
【codewars-1】字谜检测 Anagram Detection
An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia). 一个单词能通过字母重排变为另一个.Note: anagrams are case insensitive 大小写不敏感Complete the function to return true if the two arguments given are anagrams of each other; re原创 2022-03-24 11:17:46 · 215 阅读 · 0 评论 -
【codewars-2】元音字母的个数
Return the number (count) of vowels in the given string.返回给定字符中元音字母的个数。We will consider a, e, i, o, u as vowels for this Kata (but not y).aeiou作为元音字母。The input string will only consist of lower case letters and/or spaces.输入字符串仅由小写字母和空格组成。*要点要用size_原创 2022-03-24 11:38:29 · 137 阅读 · 0 评论 -
【codewars-3】从字符串形式的数字序列中找出最大和最小值
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.ExampleshighAndLow("1 2 3 4 5"); // return "5 1"highAndLow("1 2 -3 4 5"); // return "5 -3"highAndLow("1 9 3 4 -5"); //原创 2022-03-24 14:29:24 · 530 阅读 · 0 评论 -
【codewars-7】打印错误
In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from a to m.The colors used by the printer are recorded in a control string. For example a “good”原创 2022-03-25 10:53:01 · 247 阅读 · 0 评论 -
【codewars-6】检测Isograms字符串 (即无重复字符)
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. 忽略大小写的区别Example:原创 2022-03-25 10:09:01 · 209 阅读 · 0 评论 -
【无标题】
Given an array of digitals numbers, return a new array of lengthnumber containing the last even numbers from the original array (inthe same order). The original array will be not empty and will containat least “number” even numbers.For example:26, -6.原创 2022-03-24 22:23:13 · 164 阅读 · 0 评论 -
【codewars-4】路上的颠簸
Your car is old, it breaks easily. The shock absorbers are gone andyou think it can handle about 15 more bumps before it dies totally.Unfortunately for you, your drive is very bumpy! Given a stringshowing either flat road ("") or bumps (“n”), work out .原创 2022-03-24 22:00:37 · 208 阅读 · 0 评论