1.两数之和
题目
给定一个整数数组 nums
和一个目标值 target
,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
示例:
1 | 给定 nums = [2, 7, 11, 15], target = 9 |
给定一个整数数组 nums
和一个目标值 target
,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
示例:
1 | 给定 nums = [2, 7, 11, 15], target = 9 |
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.
Now given a resulting string on screen, you are supposed to list all the possible stucked keys, and the original string.
Notice that there might be some characters that are typed repeatedly. The stucked key will always repeat output for a fixed k times whenever it is pressed. For example, when k=3, from the string thiiis iiisss a teeeeeest
we know that the keys i
and e
might be stucked, but s
is not even though it appears repeatedly sometimes. The original string could be this isss a teest
.
Each input file contains one test case. For each case, the 1st line gives a positive integer k (1<k≤100) which is the output repeating times of a stucked key. The 2nd line contains the resulting string on screen, which consists of no more than 1000 characters from {a-z}, {0-9} and _
. It is guaranteed that the string is non-empty.
For each test case, print in one line the possible stucked keys, in the order of being detected. Make sure that each key is printed once only. Then in the next line print the original string. It is guaranteed that there is at least one stucked key.
1 | 3 |
1 | ei |
The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real number in [−1000,1000] and is accurate up to no more than 2 decimal places. When you calculate the average, those illegal numbers must not be counted in.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤100). Then N numbers are given in the next line, separated by one space.
For each illegal input number, print in a line ERROR: X is not a legal number
where X
is the input. Then finally print in a line the result: The average of K numbers is Y
where K
is the number of legal inputs and Y
is their average, accurate to 2 decimal places. In case the average cannot be calculated, output Undefined
instead of Y
. In case K
is only 1, output The average of 1 number is Y
instead.
1 | 7 |
1 | ERROR: aaa is not a legal number |
1 | 2 |
1 | ERROR: aaa is not a legal number |
People on Mars count their numbers with base 13:
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
Each input file contains one test case. For each case, the first line contains a positive integer N (<100). Then N lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.
For each number, print in a line the corresponding number in the other language.
1 | 4 |
1 | hel mar |
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whether a string in the shop contains all the beads she needs. She now comes to you for help: if the answer is Yes
, please tell her the number of extra beads she has to buy; or if the answer is No
, please tell her the number of beads missing from the string.
For the sake of simplicity, let's use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. For example, the 3rd string in Figure 1 is the one that Eva would like to make. Then the 1st string is okay since it contains all the necessary beads with 8 extra ones; yet the 2nd one is not since there is no black bead and one less red bead.
Each input file contains one test case. Each case gives in two lines the strings of no more than 1000 beads which belong to the shop owner and Eva, respectively.
For each test case, print your answer in one line. If the answer is Yes
, then also output the number of extra beads Eva has to buy; or if the answer is No
, then also output the number of beads missing from the string. There must be exactly 1 space between the answer and the number.
1 | ppRYYGrrYBR2258 |
1 | Yes 8 |
1 | ppRYYGrrYB225 |
1 | No 2 |
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.
Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.
Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or _
(representing the space). It is guaranteed that both strings are non-empty.
For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.
1 | 7_This_is_a_test |
1 | 7TI |
Given N rational numbers in the form numerator/denominator
, you are supposed to calculate their sum.
Each input file contains one test case. Each case starts with a positive integer N (≤100), followed in the next line N rational numbers a1/b1 a2/b2 ...
where all the numerators and denominators are in the range of long int. If there is a negative number, then the sign must appear in front of the numerator.
For each test case, output the sum in the simplest form integer numerator/denominator
where integer
is the integer part of the sum, numerator
<denominator
, and the numerator and the denominator have no common factor. You must output only the fractional part if the integer part is 0.
1 | 5 |
1 | 3 1/3 |
1 | 2 |
1 | 2 |
1 | 3 |
1 | 7/24 |
The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:
Now given a few lines spoken by the same character, can you find her Kuchiguse?
Each input file contains one test case. For each case, the first line is an integer N (2≤N≤100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.
For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write nai
.
1 | 3 |
1 | nyan~ |
1 | 3 |
1 | nai |
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in this manner we will soon end up at the number 6174
-- the black hole of 4-digit numbers. This number is named Kaprekar Constant.
For example, start from 6767
, we'll get:
1 | 7766 - 6677 = 1089 |
Given any 4-digit number, you are supposed to illustrate the way it gets into the black hole.
Each input file contains one test case which gives a positive integer N in the range (0,104).
If all the 4 digits of N are the same, print in one line the equation N - N = 0000
. Else print each step of calculation in a line until 6174
comes out as the difference. All the numbers must be printed as 4-digit numbers.
1 | 6767 |
1 | 7766 - 6677 = 1089 |
1 | 2222 |
1 | 2222 - 2222 = 0000 |
Given three integers A, B and C in [−263,263], you are supposed to tell whether A+B>C.
The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.
For each test case, output in one line Case #X: true
if A+B>C, or Case #X: false
otherwise, where X is the case number (starting from 1).
1 | 3 |
1 | Case #1: false |
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm
. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04
-- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D
, representing the 4th day in a week; the second common character is the 5th capital letter E
, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A
to N
, respectively); and the English letter shared by the last two strings is s
at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.
Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.
For each test case, print the decoded time in one line, in the format DAY HH:MM
, where DAY
is a 3-character abbreviation for the days in a week -- that is, MON
for Monday, TUE
for Tuesday, WED
for Wednesday, THU
for Thursday, FRI
for Friday, SAT
for Saturday, and SUN
for Sunday. It is guaranteed that the result is unique for each case.
1 | 3485djDkxh4hhGE |
1 | THU 14:04 |
If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and B are given in the standard form of Galleon.Sickle.Knut
(Galleon
is an integer in [0,107], Sickle
is an integer in [0, 17), and Knut
is an integer in [0, 29)).
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.
For each test case you should output the sum of A and B in one line, with the same format as the input.
1 | 3.2.1 10.16.27 |
1 | 14.1.28 |
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than half of the total area. Now given an image of resolution Mby N (for example, 800×600), you are supposed to point out the strictly dominant color.
Each input file contains one test case. For each case, the first line contains 2 positive numbers: M (≤800) and N (≤600) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0,224). It is guaranteed that the strictly dominant color exists for each input image. All the numbers in a line are separated by a space.
For each test case, simply print the dominant color in a line.
1 | 5 3 |
1 | 24 |
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2from S1. Your task is simply to calculate S1−S2 for any given strings. However, it might not be that simple to do it fast.
Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.
For each test case, print S1−S2 in one line.
1 | They are students. |
1 | Thy r stdnts. |
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.
Each input file contains one test case. For each case, the first line contains an integer N (in [3,105]), followed by N integer distances D1 D2 ⋯ DN, where Di is the distance between the i -th and the (i+1)-st exits, and DN is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M(≤104), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 107.
For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.
1 | 5 1 2 4 14 9 |
1 | 3 |
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.
The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:
1 | S1, S2, ..., S13, |
where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.
Each input file contains one test case. For each case, the first line contains a positive integer K (≤20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.
For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.
1 | 2 |
1 | S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5 |
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on { 5 31 5 88 67 88 17 }, then the second one who bets on 31 wins.
Each input file contains one test case. Each case contains a line which begins with a positive integer N (≤105) and then followed by N bets The numbers are separated by a space.
For each test case, print the winning number in a line. If there is no winner, print None
instead.
1 | 7 5 31 5 88 67 88 17 |
1 | 31 |
1 | 5 888 666 666 888 888 |
1 | None |
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1
(one) from l
(L
in lowercase), or 0
(zero) from O
(o
in uppercase). One solution is to replace 1
(one) by @
, 0
(zero) by %
, l
by L
, and O
by o
. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.
Each input file contains one test case. Each case contains a positive integer N (≤1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.
For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line There are N accounts and no account is modified
where N
is the total number of accounts. However, if N
is one, you must print There is 1 account and no account is modified
instead.
1 | 3 |
1 | 2 |
1 | 1 |
1 | There is 1 account and no account is modified |
1 | 2 |
1 | There are 2 accounts and no account is modified |
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red
, the middle 2 digits for Green
, and the last 2 digits for Blue
. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.
Each input file contains one test case which occupies a line containing the three decimal color values.
For each test case you should output the Mars RGB value in the following format: first output #
, then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a 0
to its left.
1 | 15 43 71 |
1 | #123456 |
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!
Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.
Each input contains one test case. Each case contains one positive integer with no more than 20 digits.
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.
1 | 1234567899 |
1 | Yes |
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.
Now given any two positive integers N (<105) and D (1<D≤10), you are supposed to tell if N is a reversible prime with radix D.
Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.
Each input file contains one test case. Each case consists of two positive numbers N and b, where 0<N≤109 is the decimal number and 2≤b≤109 is the base. The numbers are separated by a space.
For each test case, first print in one line Yes
if N is a palindromic number in base b, or No
if not. Then in the next line, print N as the number in base b in the form "ak ak−1 ... a0". Notice that there must be no extra space at the end of output.
1 | 27 2 |
1 | Yes |
1 | 121 5 |
1 | No |
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.
Now given any two positive integers N (<105) and D (1<D≤10), you are supposed to tell if N is a reversible prime with radix D.
The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.
For each test case, print in one line Yes
if N is a reversible prime with radix D, or No
if not.
1 | 73 10 |
1 | Yes |
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.
Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W
for win, T
for tie, and L
for lose. There was an odd assigned to each result. The winner's odd would be the product of the three odds times 65%.
For example, 3 games' odds are given as the following:
1 | W T L |
To obtain the maximum profit, one must buy W
for the 3rd game, T
for the 2nd game, and T
for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1×3.1×2.5×65%−1)×2=39.31 yuans (accurate up to 2 decimal places).
Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W
, T
and L
.
For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.
1 | 1.1 2.5 1.7 |
1 | T T W 39.31 |
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
For each test case, print the total time on a single line.
1 | 3 2 3 1 |
1 | 41 |
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
1 | 12345 |
1 | one five |
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Each input file contains one test case. Each case contains a pair of integers a and b where −106≤a,b≤106. The numbers are separated by a space.
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
1 | -1000000 9 |
1 | -999,991 |
微软的远程桌面功能从xp时代就已经有了,但是却很多人不知道要如何开启,下面就来介绍一下如何开启远程桌面功能
从上一篇文章开启Windows的远程桌面功能我们说到,Windows默认情况下只能同时登录一个账号,并且手机连上电脑,电脑就会退出登录,被踢下线,这是因为,能让多个账号远程连接到一个电脑,这个是服务器版才该有的功能,你想想,多个账号连接一台电脑,那这个电脑不应该就是服务器吗?所以想要让Windows10支持多账户远程桌面连接,我们需要一点点设置.
最好用的linux发行版
1 | set-executionpolicy remotesigned -s currentuser |