Cipe Coding Summary Part2

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.

时间: 2024-10-13 04:05:57

Cipe Coding Summary Part2的相关文章

Cipe Coding Summary Part1

1. Colorful Number:A numbercan be broken into different sub-sequence parts. Suppose a number 3245 can bebroken into parts like 3 2 4 5 32 24 45 324 245. And this number is a colorfulnumber, since product of every digit of a sub-sequence are different

山大泰克条屏写串口的核心代码(海宏原创,转载请注明)

山大泰克条屏写串口的核心代码,海宏原创,转载请注明. using System; using System.Collections.Generic; using System.Text; // using System.Runtime.InteropServices; using System.IO.Ports; using System.Windows.Forms; using iPublic; namespace sdLed { /// <summary> /// 用来连接LED的API.

VMware Coding Challenge: Possible Scores &amp;&amp; Summary: static

Combination Sum I 那道题的变体 1 /* 2 * Complete the function below. 3 */ 4 5 static int is_score_possible(int score, int[] increments) { 6 Arrays.sort(increments); 7 ArrayList<Integer> res = new ArrayList<Integer>(); 8 res.add(0); 9 helper(res, inc

PLSQL Coding Standard

Naming and Coding Standards for SQL and PL/SQL "The nice thing about standards is that you have so many to choose from." - Andrew S Tanenbaum Introduction This document is mentioned in a discussion on the OTN forums. One of the first comments be

Coding Guideline

Coding Guidelines Skip to end of metadata Created by Jose Reyes, last modified by Jerry Haagsma on Mar 29, 2017 Go to start of metadata The rules below were approved by a democratic process. Election details are at the end of each rule. 1. Coding sty

玩蛇(Python)笔记之基础Part2

玩蛇(Python)笔记之基础Part2 一.列表 1.列表 别的语言叫数组 python牛逼非要取个不一样的名字 1 age = 23 2 name = ["biubiubiu", "jiujiujiu", 22, age] 3 # namecopy = name 4 # namecopy.pop() 5 print(name) 6 # print(namecopy) List 2.列表取值 正常index 从零开始,,取倒数加负号 倒数第一就是[-1] 3.列表

Hadoop 3.0 Erasure Coding 纠删码功能预分析

前言 HDFS也可以支持Erasure Coding功能了,将会在Hadoop 3.0中发布,可以凭图为证: 在HDFS-7285中,实现了这个新功能.鉴于此功能还远没有到发布的阶段,可能后面此块相关的代码还会进行进一步的改造,因此只是做一个所谓的预分析,帮助大家提前了解Hadoop社区目前是如何实现这一功能的.本人之前也没有接触过Erasure Coding技术,中间过程也确实有些偶然,相信本文可以带给大家收获. 巧遇Hadoop 3.0 Erasure Coding 第一次主动去了解eras

tensorflow-数据流图汇总及运行次数(tf.summary)

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu Sep 6 10:16:37 2018 @author: myhaspl @email:[email protected] """ import tensorflow as tf g1=tf.Graph() with g1.as_default(): my_var=tf.Variable(1,dtype=tf.flo

summary of week

Summary of week Catalog 计算机基础 解释器 编码 数据类型 输入 输出 变量 注释 运算符 条件判断 循环 Content 计算机基础 计算机组成 软件 解释器 操作系统 : 操作系统的作用是 : 驱动硬件进行运转 硬件 ( CPU , 硬盘 , 主板 , 显示器等 ) 常见操作系统 Windows : 价格贵 xp win7 win8 win10 Windows server Linux centos : 免费 , 图形界面差 ubuntu : 个人开发 , 图形界面好