CodeWars系列题目(持续更新)
本文最后更新于:2024年7月25日 晚上
<8kyu> Opposites Attract
题目描述:
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.
Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren’t.
三目运算符一行解:
1 |
|
懒死我得了……
<7kyu> String ends with?
题目描述:
Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string).
基础小逻辑
1 |
|
<8kyu> Convert number to reversed array of digits
题目描述:
Convert number to reversed array of digits
Given a random non-negative number, you have to return the digits of this number within an array in reverse order.
就是一个小特判
1 |
|
<7 kyu> Find the stray number
题目描述:
You are given an odd-length array of integers, in which all of them are the same, except for one single number.
Complete the method which accepts such an array, and returns that single different number.
The input array will always be valid! (odd-length >= 3)
投机取巧
1 |
|
<8 kyu> Beginner - Reduce but Grow
题目描述:
Given a non-empty array of integers, return the result of multiplying the values together in order. Example:
1 |
|
选用C++支持Clang 8 C++17,用点特性
1 |
|
<8 kyu> Student’s Final Grade
题目描述:
Create a function finalGrade, which calculates the final grade of a student depending on two parameters: a grade for the exam and a number of completed projects.
This function should take two arguments: exam - grade for exam (from 0 to 100); projects - number of completed projects (from 0 and above);
This function should return a number (final grade). There are four types of final grades:
- 100, if a grade for the exam is more than 90 or if a number of completed projects more than 10.
- 90, if a grade for the exam is more than 75 and if a number of completed projects is minimum 5.
- 75, if a grade for the exam is more than 50 and if a number of completed projects is minimum 2.
- 0, in other cases
Examples(Inputs–>Output):
1 |
|
*Use Comparison and Logical Operators.
呃,判断,分支结构
1 |
|
<8 kyu> Transportation on vacation
题目描述:
After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you.
You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers.
Every day you rent the car costs $40. If you rent the car for 7 or more days, you get $50 off your total. Alternatively, if you rent the car for 3 or more days, you get $20 off your total.
Write a code that gives out the total amount for different days(d).
这就纯炫技题()
1 |
|