码迷,mamicode.com
首页 > 其他好文 > 详细

Cipe Coding Summary Part2

时间:2014-11-19 07:28:20      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:io   ar   color   os   sp   for   strong   on   div   

25. Matrix Position
Given an NxN matrix with unique integers :Find and print positions of all numbers such that it is the biggest in its row and also the smallest in its column . e.g. : In 3 x 3 with elements 
1 2 3 .
4 5 6 
7 8 9 . 
the number is 3 and position (1,3)

Steps

brute force, first find row find and to see if its the col min

 

26. Replace String
Froma given string, replace all instances of ‘a‘ with ‘one‘ and ‘A‘ with ‘ONE‘.
Example Input: " A boy is playing in a garden"
Example Output: " ONE boy is playing in onegarden"
-- Not that ‘A‘ and ‘a‘ are to be replaced only when theyare single characters, not as part of another word.

Steps

s.replaceAll("\\b(a)", "one"),  \b match word with boundary


27. Replace Words
Given a string. Replace the words whose length>=4and is even, with a space between the two equal halves of the word. Consideronly alphabets for finding the evenness of the word 
I/P "A person can‘t walk in this street" 
O/P "A per son ca n‘t wa lk in th is str eet"

s.toCharArray

注意substring的index就行

 


28. Replace AEIOU
Replace a,e,i,o,u with A,E,I,O,U.
At most four eligible letters from the rearof the string are replaced.
The first three eligible letters in thestring are always exempted from replacement.


29. Security Keypad
There is a security keypad at the entrance ofa building. It has 9 numbers 1 - 9 in a 3x3 matrix format. 
1 2 3 
4 5 6 
7 8 9 
The security has decided to allow one digit error for a person but that digitshould be horizontal or vertical. Example: for 5 the user is allowed to enter2, 4, 6, 8 or for 4 the user is allowed to enter 1, 5, 7. IF the security codeto enter is 1478 and if the user enters 1178 he should be allowed. Write afunction to take security code from the user and print out if he should beallowed or not.
30. Calendar
Get a date (mon/day/year) from user. Printexact the week of dates (Sun to Sat). ex) input: 2/20/2001 if the day isWednesday 
output: Sunday 2/17/2001 . 
Monday 2/18/2001 
Tuesday 2/19/2001 
Wednesday 2/20/2001 
Thursday 2/21/2001 
Friday 2/22/2001 
Saturday 2/23/2002
31. Seeds Number
Find the seed of a number. 
Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible seedfor a given number.
32. Tic Tac Toe
N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If 3 consecutive samecolor found, that color will get 1 point. So if 4 red are vertically then pointis 2. Find the winner.
33. Fill a “magic square”matrix.
A magic square of order n is an arrangement of thenumbers from 1 to n^2 in an n by n matrix with each number occurring exactlyonce so that each row, each column and each main diagonal has the same sum. Then should be an odd number. In the middle cell of the top row, fill number 1.Then go to above row and right column, and fill following number 2. If it’s outof boundary, go to the opposite row or column. If the next cell is alreadyoccupied, go to the cell below this cell and fill following number. An exampleof 5*5 grid is like this for the first 9 numbers:
0 0 1 8 0
0 5 7 0 0
4 6 0 0 0
0 0 0 0 3
0 0 0 2 9
34. Bull and Cows Game
There’s a word guessing game. One personthink a word, and the other one guess a word, both words have the same length.The person should return the number of bulls and cows for the guessing. Bullsrepresent the number of same characters in the same spots, whereas cowsrepresent the number of characters guessed right but in the wrong spots. Writea program with two input strings, return the number of bulls and cows.
35. Palindromes
Print all palindromes of size greater than orequal to 3 of a given string. (How to do it with DP)?
36. Unique Number
Write, efficient code for extracting uniqueelements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9)-> (1, 3, 5, 9).
37. Subtraction of two Arrays
Suppose you want to do the subtraction of twonumbers. Each digit of the numbers is divided and put in an array. Like A=[1,2, 3, 4, 5], B=[4, 5, 3, 5]. You should output an array C=[7, 8, 1, 0].Remember that your machine can’t hand numbers larger than 20.
38. Basketball Hit Rate
The hit rate of the basketball game is givenby the number of hits divided by the number of chances. For example, youhave 73 chances but hit 15 times, then your hit rate is 15/73=0.205 (keep the last3 digits). On average, you have 4.5 chances in each basketball game. Assume thetotal number of games is 162. Write a function for a basketball player. Hewill input the number 
of hits he has made, the number of chances he had, and the number of remaininggames. The function should return the number of future hits, so that hecan refresh his hit rate to 0.45
39. Clock Angle
We are given a specific time(like 02:23), weneed to get the angle between hour and minute(less than 180)
40. Jump Chess
There’sa N*N board, two players join the jump game. The chess could go vertically andhorizontally. If the adjacent chess is opponent player’s and the spot besidethat is empty, then the chess could jump to that spot. One chess could not beenjumped twice. Given the position of the spot on the board, write the program tocount the longest length that chess could go.
41. Decimal Number
Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places are allowed. Theoutput should be an irreducible fraction. E.g.: If the user enters 0.35,the irreducible fraction will be 7/20.
42. Continuous Alphabets
Printcontinuous alphabets from a sequence of arbitrary alphabets . @1point 3 acres
For example: 
Input: abcdefljdflsjflmnopflsjflasjftuvwxyz . Waral 
Output: abcdef; mnop; tuvwxyz
Input: AbcDefljdflsjflmnopflsjflasjftuvWxYz 
Output: abcdef; mnop; tuvwxyz
43. Substring Addition
Write a program to add the substring. eg :say you have alist {1 7 6 3 5 8 9 } and user is entering a sum 16. Output should display(2-4) that is {7 6 3} cause 7+6+3=16.
44. Balanced String
Given a string that has{},[],() and characters.Check if the string is balanced. E.g. {a[(b)]} is balanced. {a[(b])} isunbalanced.
45. RGBCompare
Given a string of RGB value (rr, gg, bb)which represents in hexadecimal. Compare if rr or gg or bb is the biggest, ortwo of those values are equal and larger than the third one, or three valuesare equal with each other.
46. Edge Detection
Two-dimensional array representation of animage can also be represented by a one-dimensional array of W*H size, where Wrepresent row and H represent column size and each cell represent pixel valueof that image. You are also given a threshold X. For edge detection, you haveto compute difference of a pixel value with each of it‘s adjacent pixel andfind maximum of all differences. And finally compare if that maximum differenceis greater than threshold X. if so, then that pixel is a edge pixel and have todisplay it.
47. Plus Equal Number
Given a number find whether the digits in thenumber can be used to form an equation with + and ‘=‘. That is if the number is123, we can have a equation of 1+2=3. But even the number 17512 also forms theequation 12+5=17.
48. Octal and Decimal Palindrome
. 1point 3acres 
The decimal and octal values of some numbersare both palindromes sometimes. Find such numbers within a given range.

Cipe Coding Summary Part2

标签:io   ar   color   os   sp   for   strong   on   div   

原文地址:http://www.cnblogs.com/superbo/p/4107320.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!