Tải bản đầy đủ (.docx) (295 trang)

Báo cáo project 1 copy

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.21 MB, 295 trang )

Contents
Câu 1 : Fibonacci......................................................................................................................................2
Câu 2 : Sum of Digits / Digital Root..................................................................................................2
Câu 3 : Fibonacci......................................................................................................................................3
Câu 4 : Find the next perfect square!..............................................................................................4
Câu 5 : Reverse words...........................................................................................................................5
Câu 6 : Convert number to reversed array of digits.................................................................6
Convert number to reversed array of digits..............................................................................6
Câu 7 : Unique In Order.........................................................................................................................7
Cau 8 : Bouncing Balls...........................................................................................................................8
Câu 9 : Don't give me five!............................................................................................................10
Don't give me five!............................................................................................................................10
Câu 10 : Build Tower.............................................................................................................................11
Câu 11 : String ends with?..................................................................................................................13
Câu 12 : Friend or Foe?........................................................................................................................13
Câu 13 : Two fighters, one winner...................................................................................................14
Câu 14: Remove the minimum........................................................................................................16
Câu 15 : Is this a triangle?.................................................................................................................17
Câu 16 : Find the capitals...................................................................................................................17
Câu 17 : Count the divisors of a number.....................................................................................18
Câu 18 : Sort array by string length...............................................................................................19
Câu 19 : Testing 1-2-3...........................................................................................................................20
Câu 20 : Number of People in the Bus...........................................................................................20
Câu 21 : Odd or Even?..........................................................................................................................21
Câu 22 : Check the exam...................................................................................................................22
Câu 23 : Remove anchor from URL.................................................................................................24
Câu 24 : Anagram Detection.............................................................................................................24
Câu 25 : Round up to the next multiple of 5...............................................................................25
Câu 26 : You're a square!....................................................................................................................26
Câu 27 : Maximum Length Difference...........................................................................................27
Câu 28 : Get the Middle Character.................................................................................................28


Câu 29 : Alternate capitalization.................................................................................................29
Câu 30 : Summing a number's digits.............................................................................................30
Câu 31 : Breaking chocolate problem...........................................................................................31
Câu 32 : Money, Money, Money.......................................................................................................32
Câu 33 : Two Oldest Ages....................................................................................................................34


Câu 34 : Factorial...................................................................................................................................35
Câu 35 : Are the numbers in order?...............................................................................................35
Are the numbers in order?..............................................................................................................35
Câu 36 : Deodorant Evaporator........................................................................................................37
Câu 37 : Exes and Ohs.........................................................................................................................37
Câu 38 : Sum of all the multiples of 3 or 5..............................................................................38
Câu 39 : The Coupon Code................................................................................................................39
Câu 40 : Simple Fun #176: Reverse Letter..................................................................................40
Câu 41 : Small enough? - Beginner................................................................................................41
Câu 42 : Sum of angles.......................................................................................................................42
Câu 44 : Make a function that does arithmetic!........................................................................43
Câu 45 : Fix string case........................................................................................................................44
Câu 46 : Sort Numbers.........................................................................................................................46
Câu 47 : List Filtering............................................................................................................................46
Câu 48 : Alphabet war..........................................................................................................................47
Câu 49 : Descending Order................................................................................................................49
Câu 50 : Count the Digit......................................................................................................................49
Câu 51 : Binary Addition......................................................................................................................51
Câu 52 : Sum of numbers from 0 to N...........................................................................................51
Câu 53 : Love vs friendship................................................................................................................53
Câu 55 : Highest and Lowest.............................................................................................................55
Câu 56 : Maximum Multiple...........................................................................................................56
Câu 58 : Printer Errors..........................................................................................................................58

Câu 59 : Predict your age!..................................................................................................................59
Câu 60 : Sum of two lowest positive integers............................................................................60
Câu 61 : Square Every Digit...............................................................................................................61
Câu 62 : Regex validate PIN code....................................................................................................62
Câu 63 : Beginner Series #3 Sum of Numbers..........................................................................63
Câu 64 : Shortest Word........................................................................................................................64
Câu 66 : Jaden Casing Strings...........................................................................................................65
Câu 67 : Row Weights.......................................................................................................................66
Câu 68 : Remove duplicate words...................................................................................................68
Câu 69 : Find the vowels.....................................................................................................................69
Câu 70 : Sum of a sequence..............................................................................................................70
Câu 71 : Volume of a Cuboid.............................................................................................................71
Câu 72 : Disemvowel Trolls.................................................................................................................72
Câu 73 : Speed Control........................................................................................................................72


Câu 74 : Mumbling.................................................................................................................................74
Câu 75 : Find the stray number........................................................................................................75
Câu 76 : I love you, a little , a lot, passionately ... not at all............................................76
Câu 77 : Categorize New Member...................................................................................................77
Câu 78 : Greet Me..................................................................................................................................78
Câu 79 : Sum of Triangular Numbers.............................................................................................79
Câu 80 : Alphabet symmetry.............................................................................................................80
Câu 81 : Gauß needs help! (Sums of a lot of numbers).....................................................81
Câu 82 : Sum of odd numbers......................................................................................................81
Câu 83 : Thinkful - String Drills: Repeater...............................................................................82
Câu 84 : Isograms..................................................................................................................................83
Câu 85 : Sort the Gift Code................................................................................................................84
Câu 86 : Largest 5 digit number in a series................................................................................85
Câu 87 : Balanced Number (Special Numbers Series #1 )...............................................86

Câu 88 : Fizz Buzz..............................................................................................................................87
Câu 89 : Power of two...........................................................................................................................88
Câu 90 : The highest profit wins!....................................................................................................89
Câu 91 : Simple Fun #152: Invite More Women?......................................................................90
Câu 92 :Growth of a Population....................................................................................................91
Câu 93 : Bumps in the Road..............................................................................................................93
Câu 94 : Moves in squared strings (I)............................................................................................94
Câu 95 : Number of Decimal Digits................................................................................................96
Câu 96 : Alphabetical Addition.....................................................................................................96
Câu 97 : Build a square.......................................................................................................................98
Câu 97 : Convert an array of strings to array of numbers....................................................99
Câu 98 : Simple beads count.............................................................................................................99
Câu 99 : Ordered Count of Characters....................................................................................100
Câu 100 : Sum of Cubes.....................................................................................................................101
Câu 101 : Leap Years...........................................................................................................................102
Câu 102 : Functional Addition..........................................................................................................103
Câu 103 : Averages of numbers.....................................................................................................103
Câu 104 : max diff - easy...................................................................................................................104
Câu 105 : Most digits...........................................................................................................................105
Câu 106 : My Language Skills.....................................................................................................106
Câu 107 : Switcheroo..........................................................................................................................107
Câu 108 : Find the nth Digit of a Number...................................................................................108
Câu 109 : Lost number in number sequence............................................................................109


Câu 110 : JavaScript Array Filter.....................................................................................................109
Câu 111 : Reverse a Number...........................................................................................................110
Câu 112 : Largest pair sum in array..............................................................................................111
Câu 113 : Strong Number (Special Numbers Series #2)......................................................112
Câu 114 : Currying functions: multiply all elements in an array......................................112

Câu 115 : Simple Fun #74: Growing Plant.................................................................................113
Câu 116 : Disarium Number (Special Numbers Series #3).................................................116
Câu 117 : Alternate case...............................................................................................................117
Câu 118 : Boiled Eggs.........................................................................................................................118
Câu 119 : Array element parity.......................................................................................................119
Câu 120 : Greatest common divisor.............................................................................................120
Câu 121 : Rotate for a Max...............................................................................................................121
Câu 122 : A Rule of Divisibility by 7..............................................................................................122
Câu 123 : Going to the cinema...................................................................................................124
Câu 124 : Simple remove duplicates............................................................................................125
Câu 125 : Sum of array singles.......................................................................................................126
Câu 126 : Factorial...............................................................................................................................127
Câu 127 : Indexed capitalization...............................................................................................127
Câu 128 : Filter the number..............................................................................................................128
Câu 129 : Incrementer........................................................................................................................129
Câu 130 : Cat and Mouse - Easy Version....................................................................................130
Câu 131 : Complementary DNA......................................................................................................130
Câu 132 : Complete The Pattern #1.............................................................................................131
Câu 133 : Difference Of Squares....................................................................................................133
Câu 134 : Convert a linked list to a string..................................................................................134
Câu 135 : Narcissistic Numbers......................................................................................................136
Câu 136 : Unlucky Days.....................................................................................................................137
Câu 137 : Word values........................................................................................................................139
Câu 138 : Basic Calculator................................................................................................................140
Câu 139 : Discover The Original Price.....................................................................................141
Câu 140 : All Inclusive?......................................................................................................................141
Câu 141 : Expressions Matter..........................................................................................................143
Câu 142 : Maximum Product............................................................................................................144
Câu 143 : Parts of a list......................................................................................................................145
Câu 144 : Digital cypher....................................................................................................................147

Câu 145 : Basic Sequence Practice...............................................................................................149
Câu 146 : All unique............................................................................................................................151


Câu 147 : Numbers to Letters.........................................................................................................151
Câu 148 : Simple string characters...............................................................................................152
Câu 149 : Sort by Last Char.............................................................................................................153
Câu 150 : Compare Strings by Sum of Chars............................................................................153
Câu 151 : All Star Code Challenge #22.......................................................................................154
Câu 152 : Digitize.................................................................................................................................155
Câu 153 : Count all the sheep on farm in the heights of New Zealand.........................156
Câu 154 : Numbers in strings......................................................................................................157
Câu 155 : Return the first M multiples of N...............................................................................158
Câu 156 : Recursion #1 - Factorial................................................................................................159
Câu 157 : Even or Odd........................................................................................................................159
Câu 158 : The Office II - Boredom Score.....................................................................................160
Câu 159 : Split In Parts...................................................................................................................161
Câu 160 : Sum of integers in string..............................................................................................162
Câu 162 : Digits explosion................................................................................................................164
Câu 162 : The old switcheroo..........................................................................................................165
Câu 163 : Counting Array Elements..............................................................................................166
Câu 164 : Responsible Drinking......................................................................................................167
Câu 165 : Multiply characters..........................................................................................................168
Câu 166 : Odd-Even String Sort......................................................................................................169
Câu 167 : Nth power rules them all!.............................................................................................170
Câu 168 : Drying Potatoes................................................................................................................171
Câu 169 : Average Scores.............................................................................................................172
Câu 170 : Return the closest number multiple of 10.............................................................172
Câu 171 : Smallest value of an array...........................................................................................173
Câu 172 : The wheat/rice and chessboard problem..........................................................174

Câu 172 : Building blocks..................................................................................................................175
Câu 174 : Substituting Variables Into Strings: Padded Numbers.................................177
Câu 175 : Case Swapping..................................................................................................................178
Câu 176 : Looking for a benefactor...............................................................................................178
Câu 177 : Basic Math (Add or Subtract)......................................................................................180
Câu 178 : SevenAte9......................................................................................................................181
Câu 179 : Clean up after your dog................................................................................................181
Câu 180 : Say hello!.............................................................................................................................183
Câu 181 : Reverse the bits in an integer....................................................................................183
Câu 182 : Unique string characters..........................................................................................184
Câu 183 : Regexp Basics - is it a vowel?.....................................................................................185


Câu 184 : Find the lucky numbers.................................................................................................186
Câu 185 : Simple Fun #2: Circle of Numbers............................................................................186
Câu 186 : By 3, or not by 3? That is the question . . ............................................................188
Câu 187 : Last Survivor......................................................................................................................189
Câu 188 : Building Strings From a Hash......................................................................................190
Câu 189 : Number Of Occurrences................................................................................................191
Câu 190 : Exclamation marks series #13: Count the number of exclamation marks
and question marks, return the product.................................................................................191
Câu 191 : Simple Fun #37: House Numbers Sum...................................................................192
Câu 192 : Interview Question (easy)............................................................................................194
Câu 193 : Credit card issuer checking.........................................................................................197
Câu 194 : Valid Spacing.....................................................................................................................198
Câu 195 : Simple string reversal....................................................................................................199
Câu 196 : Letterbox Paint-Squad....................................................................................................200
Câu 197 : Check three and two.......................................................................................................202
Câu 198 : Character Counter...........................................................................................................203
Câu 199 : Inspiring Strings...........................................................................................................204

Câu 200 : Complete The Pattern #2........................................................................................205
Câu 201 : makeBackronym...............................................................................................................207
back·ro·nym........................................................................................................................................207
Câu 202 : Remove All The Marked Elements of a List...........................................................208
Câu 203 : Evens times last...............................................................................................................209
Câu 204 : Insert dashes.....................................................................................................................210
Câu 205 : Initialize my name...........................................................................................................211
Câu 206 : Computer problem series #1: Fill the Hard Disk Drive....................................212
Câu 207 : getNames().........................................................................................................................213
Câu 208 : Nice Array............................................................................................................................214
Câu 209 : Enumerable Magic #5- True for Just One?.............................................................216
Câu 210 : Holiday III - Fire on the boat........................................................................................216
Câu 211 : Volume of a Cuboid.........................................................................................................217
Câu 212 : Reverse words...................................................................................................................217
Câu 214 : Find the next perfect square!......................................................................................218
Câu 215 : Ones and Zeros.................................................................................................................219
Câu 216 : Flatten and sort an array..............................................................................................220
Câu 217 : Coding Meetup #1 - Higher-Order Functions Series - Count the number of
JavaScript developers coming from Europe..........................................................................221
Câu 218 : Coloured Triangles...........................................................................................................222
219 : Char Code Calculation...........................................................................................................223


Câu 220 : Spacify..................................................................................................................................224
Câu 222 : The Office I - Outed........................................................................................................226
Câu 223 : Coding Meetup #2 - Higher-Order Functions Series - Greet developers. .226
Câu 234 : Simple consecutive pairs..............................................................................................228
Câu 225 : Halving Sum.......................................................................................................................229
Câu 227 : Squares sequence...........................................................................................................230
Câu 228 : Count the Characters.....................................................................................................230

Câu 229 : Don't give me five!..........................................................................................................231
Don't give me five!..........................................................................................................................231
Câu 230 : Series of integers from m to n....................................................................................232
Câu 231 : Volume of a Cuboid.........................................................................................................232
Câu 233 : The Office IV - Find a Meeting Room........................................................................233
Câu 234 : Help the Fruit Guy............................................................................................................234
Câu 235 : Sort arrays - 1....................................................................................................................234
Câu 236 : Covfefe.................................................................................................................................235
Câu 237 : ATM........................................................................................................................................235
Câu 238 : Double Sort.........................................................................................................................236
Câu 239 : 16+18=214........................................................................................................................237
Câu 240 : Broken sequence..............................................................................................................238
Câu 241 : Replace every nth............................................................................................................239
Câu 242 : How many arguments....................................................................................................240
Câu 243 : Formatting decimal places #1....................................................................................241
Câu 244 : Summy.................................................................................................................................241
Câu 245 : Find Screen Size...............................................................................................................242
The Challenge....................................................................................................................................242
Câu 246 : Find Count of Most Frequent Item in an Array.....................................................243
Câu 247 : Remove consecutive duplicate words.....................................................................243
Câu 248 : Find all pairs.......................................................................................................................244
Câu 249 : Correct the time-string..................................................................................................245
Câu 250 : Bingo ( Or Not ).................................................................................................................246
Câu 251 : Spoonerize Me...................................................................................................................247
Câu 252 : Stanton measure..............................................................................................................248
Câu 253 : Arithmetic progression..................................................................................................248
Câu 254 : Numbers with this digit inside....................................................................................249
Câu 255 : String Merge!...............................................................................................................250
Câu 256 : lucky number.....................................................................................................................251
Câu 257 : Scaling Squared Strings................................................................................................251



Câu 258 : Max-min arrays.................................................................................................................253
Câu 259 : Plus - minus - plus - plus - ... - Count.......................................................................254
Câu 260 : Pandemia �.........................................................................................................................254
Câu 261 : Calculate mean and concatenate string................................................................256
Câu 262 : The fusc function -- Part 1............................................................................................257
Câu 263 : The Office III - Broken Photocopier...........................................................................258
Câu 265 : Last........................................................................................................................................259
Câu 266 : Is n divisible by (...)?.......................................................................................................259
Câu 267 : "Very Even" Numbers.....................................................................................................260
Câu 268 : Thinking & Testing: A and B?.......................................................................................261
Câu269 : Linked Lists - Push & BuildOneTwoThree.................................................................261
Câu 270 : Number-Star ladder........................................................................................................262
Câu 271 : Powers of 2.........................................................................................................................264
Câu 272 : Even numbers in an array............................................................................................264
Câu 273 : Coding Meetup #3 - Higher-Order Functions Series - Is Ruby coming?....265
Câu 274 : Coding Meetup #11 - Higher-Order Functions Series - Find the average
age..........................................................................................................................................................266
Câu 275 : Coding Meetup #5 - Higher-Order Functions Series - Prepare the count of
languages............................................................................................................................................267
Câu 276 : Debug Sum of Digits of a Number............................................................................268
Câu 277 : Divide and Conquer........................................................................................................269
Câu 278 : V A P O R C O D E.............................................................................................................269
Câu 279 : Sum even numbers.........................................................................................................270
Câu 280 : All Star Code Challenge #3.........................................................................................270
Câu 281 : Coding Meetup #6 - Higher-Order Functions Series - Can they code in the
same language?................................................................................................................................271
Câu 282 : Nth Root of a Number....................................................................................................272
Câu 283 : Consecutive items...........................................................................................................272

Câu 284 : Head, Tail, Init and Last.................................................................................................273
Câu 285 : Find min and max............................................................................................................275
Câu 286 : Find Nearest square number..................................................................................275
Câu 287 : Find the middle element...............................................................................................275
Câu 288 : Consecutive Vowels in a String..............................................................................276
Câu 289 : CSV representation of array........................................................................................277
Câu 290 : Add property to every object in array.....................................................................278
Câu 291 : Rock Paper Scissors!.......................................................................................................279
Câu 292 : Help Suzuki complete his chores!.............................................................................280
Câu 293 : Scrabble Score..................................................................................................................281


Câu 294 : Merge two sorted arrays into one.............................................................................282
Câu 295 : The fusc function -- Part 1............................................................................................283
Câu 296 : Dot Calculator....................................................................................................................284
Câu 297 : Find Nearest square number.......................................................................................285
Câu 298 : Powers of 2.........................................................................................................................285
Câu 299 : L1: Set Alarm.....................................................................................................................286
Câu 300 : Tổng số điểm.....................................................................................................................287

Câu 1 : Fibonacci
Create function fib that returns n'th element of Fibonacci sequence (classic
programming task).

INPUT : nhập số n
OUTPUT : in ra dãy fibonacci
B1 : khai báo f0 = 0 , f1 = 1 , fn = 1
B2 : nếu n < 0 trả về -1 , n = 0 hoặc n = 1 thì trả về n
B3 : nếu n > 2 thì thực hiện vịng lặp for .
gán f0 = f1 , f1 = fn , fn = f0 + f1 và trả về fn . kết thức thuật toán



Câu 2 : Sum of Digits / Digital Root
Given n , take the sum of the digits of n . If that value has more than one
digit, continue reducing in this way until a single-digit number is produced.
The input will be a non-negative integer.

Examples
16
942
132189
493193

-->
-->
-->
-->

1
9
1
4

+
+
+
+

6
4

3
9

=
+
+
+

7
2 = 15 --> 1 + 5 = 6
2 + 1 + 8 + 9 = 24 -->
3 + 1 + 9 + 3 = 29 -->

2 + 4 = 6
2 + 9 = 11

INPUT : nhập số number
OUTPUT : tính tổng các chữ số của n cho đến khi tổng là 1 số nhỏ hơn 10
B1 : khai báo sum , reminder
B2 : thực hiện vòng lặp while với number > 0 thì reminder = number % 10
sum = reminder + sum
number = number / 10

-->

1 + 1 = 2


B3 : sử dụng if với sum > 9 thì thực hiện lại bước 2 , kết thúc thuật toán


Câu 3 : Fibonacci
Create function fib that returns n'th element of Fibonacci sequence (classic
programming task).

INPUT : nhập vào int n
OUTPUT : trả về chuỗi phần tử n của chuỗi fib

Câu 4 : Find the next perfect
square!
You might know some pretty large perfect squares. But what about the
NEXT one?


Complete the findNextSquare method that finds the next integral perfect
square after the one passed as a parameter. Recall that an integral perfect
square is an integer n such that sqrt(n) is also an integer.
If the parameter is itself not a perfect square then -1 should be returned.
You may assume the parameter is non-negative.
Examples:(Input --> Output)
121 --> 144
625 --> 676
114 --> -1 since 114 is not a perfect square

INPUT : nhập số n
OUTPUT : in ra bình phương của ( + 1 )
B1 : nhập n , khai báo a
B2 : nếu n > 0 thì lấy căn của n + 1 , sau đó gán vào a
B3 : bình phương a , sau đó gán vào b
B4 : in ra b ,kết thúc thuật toán


Câu 5 : Reverse words


Complete the function that accepts a string parameter, and reverses each
word in the string. All spaces in the string should be retained.

Examples
"This is an example!" ==> "sihT si na !elpmaxe"
"double spaces"
==> "elbuod secaps"

INPUT : nhập chuỗi string
OUTPUT : đảo ngước từng chữ trong chuỗi string
B1 : nhập chuỗi string
B2 : khai báo mảng xauArray kiểu char để tách từ trong chuỗi
B3 : tạo đối tượng reverve đầu vào xauArray sau đó trả về reverve , kết thúc thuật tốn

Câu 6 : 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.


Example(Input => Output):
348597 => [7,9,5,8,4,3]
0 => [0]

Câu 7 : Unique In Order
Implement the function unique_in_order which takes as argument a

sequence and returns a list of items without any elements with the same
value next to each other and preserving the original order of elements.
For example:


uniqueInOrder("AAAABBBCCDAABBB") == {'A', 'B', 'C', 'D', 'A', 'B'}
uniqueInOrder("ABBCcAD")

== {'A', 'B', 'C', 'c', 'A', 'D'}

uniqueInOrder([1,2,2,3,3])

== {1,2,3}

INPUT : nhập chuỗi string inputString
OUTPUT : trả về mảng loại bỏ các kí tự trùng lặp
B1 : khai báo chuỗi string inputString , resultString
B2 : thực hiện vòng lặp for => sử dụng if với !resultString.Contains(inputString[i]) thì
resultString +=inputString[i] + ‘’,”
B4 : trả về , kết thúc thuật toán

Cau 8 : Bouncing Balls


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 1.5 meters from the ground.
How many times will the mother see the ball pass in front of her window

(including when it's falling and bouncing?
Three conditions must be met for a valid experiment:


Float parameter "h" in meters must be greater than 0



Float parameter "bounce" must be greater than 0 and less than 1



Float parameter "window" must be less than h.

If all three conditions above are fulfilled, return a positive integer,
otherwise return -1.
Note:

The ball can only be seen if the height of the rebounding ball is
strictly greater than the window parameter.
Examples:
- h = 3, bounce = 0.66, window = 1.5, result is 3
- h = 3, bounce = 1, window = 1.5, result is -1
(Condition 2) not fulfilled).


INPUT : nhập h , bounce = 0.66 , window = 1.5
OUTPUT : số lần người mẹ thấy bóng sau khi bóng rơi
B1 : nhập h , bounce = 0.66 , window = 1.5
B2 : thực hiện vòng lặp while () , mỗi lần bóng rơi thì gán lại chiều cao h và tính được số lần nhìn thấy

bóng qua cửa số . kết thức thuật toánp

Câu 9 : Don't give me five!
Don't give me five!
In this kata you get the start number and the end number of a region and
should return the count of all numbers except numbers with a 5 in it. The
start and the end number are both inclusive!
Examples:
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12

The result may contain fives. ;-)
The start number will always be smaller than the end number. Both
numbers can be also negative!
I'm very curious for your solutions and the way you solve it. Maybe
someone of you will find an easy pure mathematics solution.


Have fun coding it and please don't forget to vote and rank this kata! :-)
I have also created other katas. Take a look if you enjoyed this kata!

INPUT : nhập 2 số nguyên dương
OUTPUT : tính số các số trong khoảng 2 số
B1 : khai báo biến tổng
B2 :thực hiện vòng lặp for
B3 : nếu thực hiện đến số 5 , loại bỏ đi số 5 và tiếp tục thực hiên vịng lặp , kết thúc thuật tốn

Câu 10 : Build Tower
Build Tower
Build a pyramid-shaped tower given a positive integer number of floors . A

tower block is represented with "*" character.


For example, a tower with 3 floors looks like this:
[
"

*

",

" *** ",
"*****"
]

And a tower with 6 floors looks like this:
[
"

*

",

"

***

",

"


*****

",

"

*******

",

" ********* ",
"***********"
]


INPUT :nhập vào nFloors
OUTPUT : trả về hình tháp
B1 : khai báo danh sách List <string> primes
B2 : thực hiện vòng lặp for

Câu 11 : 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).
Examples:
solution('abc', 'bc') // returns true
solution('abc', 'd') // returns false

INPUT : nhập 2 chuỗi string
OUTPUT : trả về true false so sánh chuỗi string 2 là chuỗi kết thúc của chuỗi string 1

B1 : sử dụng hàm contains để so sánh str và ending


Câu 12 : Friend or Foe?
Make a program that filters a list of strings and returns a list with only your
friends name in it.
If a name has exactly 4 letters in it, you can be sure that it has to be a
friend of yours! Otherwise, you can be sure he's not...
Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"]
i.e.
friend ["Ryan", "Kieran", "Mark"] `shouldBe` ["Ryan", "Mark"]

INPUT : nhập vào mảng string
OUTPUT : trả về mảng string tên có 4 chữ cái
B1 : khai báo mảng listOfFriends
B2 : thực hiện vòng lặp foreach , nếu độ dài của mảng là 4 thì add vào listOfFriend ,trả về
listOfFriend , kết thúc thuật toán

Câu 13 : Two fighters, one winner.
Create a function that returns the name of the winner in a fight between
two fighters.


Each fighter takes turns attacking the other and whoever kills the other
first is victorious. Death is defined as having health <= 0 .
Each fighter will be a Fighter object/instance. See the Fighter class below
in your chosen language.
Both health and damagePerAttack ( damage_per_attack for python) will be
integers larger than 0 . You can mutate the Fighter objects.


Example:
declare_winner(Fighter("Lew", 10, 2), Fighter("Harry", 5, 4), "Lew") =>
"Lew"

Lew attacks Harry; Harry now has 3 health.
Harry attacks Lew; Lew now has 6 health.
Lew attacks Harry; Harry now has 1 health.
Harry attacks Lew; Lew now has 2 health.
Lew attacks Harry: Harry now has -1 health and is dead. Lew wins.
public class Fighter {
public string Name;
public int Health, DamagePerAttack;
public Fighter(string name, int health, int damagePerAttack) {
this.Name = name;
this.Health = health;
this.DamagePerAttack = damagePerAttack;
}
}


INPUT : 2 võ sĩ và dame của 2 võ sĩ
OUTPUT : trả về người thắng giữa 2 võ sĩ

Câu 14: Remove the minimum
The museum of incredible dull things
The museum of incredible dull things wants to get rid of some exhibitions.
Miriam, the interior architect, comes up with a plan to remove the most
boring exhibitions. She gives them a rating, and then removes the one
with the lowest rating.
However, just as she finished rating all exhibitions, she's off to an

important fair, so she asks you to write a program that tells her the ratings
of the items after one removed the lowest one. Fair enough.

Task
Given an array of integers, remove the smallest value. Do not mutate
the original array/list. If there are multiple elements with the same
value, remove the one with a lower index. If you get an empty array/list,
return an empty array/list.
Don't change the order of the elements that are left.

Examples
* Input: [1,2,3,4,5], output= [2,3,4,5]
* Input: [5,3,2,1,4], output = [5,3,2,4]
* Input: [2,2,1,2,1], output = [2,2,2,1]


INPUT : nhập vào mảng số
OUTPUT : in ra mảng số loại đi số nhỏ nhất trong mảng
B1 : thực hiện câu lệnh điều kiện if , sử dụng hàm remove để lạo bỏ số min có trong mảng , kết thúc
thuật toán

Câu 15 : Is this a triangle?
Câu Implement a function that accepts 3 integer values a, b, c. The
function should return true if a triangle can be built with the sides of given
length and false in any other case.
(In this case, all triangles must have surface greater than 0 to be
accepted).

INPUT : nhập độ dài 3 cạnh của tam giác
OUTPUT : trả về true hoặc false nếu 3 cạnh đó hợp thành 1 tam giác

B1 : trả về điều kiện a + b >c ,b + c > a , a +c > b

Câu 16 : Find the capitals


Write a function that takes a single string ( word ) as argument. The
function must return an ordered list containing the indexes of all capital
letters in the string.

Example
Assert.AreEqual(Kata.Capitals("CodEWaRs"), new int[]{0,3,4,6});

INPUT : nhập vào chuỗi string
OUTPUT : trả về số thứ tự của kí tự in hoa
B1 : khai báo mảng List
B2 : thực hiện vòng lặp for
B3 : sử dụng câu lệnh if , nếu kí tự thứ i in hoa thì thêm i vào mảng List
B4 : trả về mảng , kết thúc thuật toán .

Câu 17 : Count the divisors of a
number
Count the number of divisors of a positive integer n .
Random tests go up to n = 500000 .

Examples (input --> output)
4 --> 3 (1, 2, 4)
5 --> 2 (1, 5)
12 --> 6 (1, 2, 3, 4, 6, 12)



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×