get不到其中的逻辑，为什么digit_seen[digit]为真，就能表示digit至少出现过2次

#include
#include
int main(void)//检查数中重复出现的数字
{
bool digit_seen={false}
int digit;
long n;
printf("Enter a number:");
scanf("%d",&n);
while(n>0){
digit=n%10；
if (digit_seen[digit])
break'
digit_seen[digit]=true;
n/=10;
}
if (n>0)
printf("Repeatd digit\n");
else
printf("No repeated digit\n");
return 0;
}

3个回答

digit_seen[digit]=true;如果是第一次出现的话就会执行这个语句，将digit_seen[digit]设置为true，，，如果第二次出现digit的时候，数组中的标记为已经被置为true了

digit_seen中存储的布尔型数据可以理解为对应的0~9的数字是否出现过，循环中如果出现相应的数字就把它设为true，如果再次出现就退出循环，最后判断输入的数是否每位都处理过变成0

digit_seen[digit]=true;如果是第一次出现的话就会执行这个语句，将digit_seen[digit]设置为true，，，如果第二次出现digit的时候，数组中的标记为已经被置为true了 #include<stdio.h> #define true 1 #define false 0 typedef int bool; int main(void)//检查数中重复出现的数字 { bool digit_seen={false}; int digit; long n; printf("Enter a number:"); scanf("%d",&n); while(n>0){ digit=n%10; if (digit_seen[digit]==true) break; digit_seen[digit]=true; n/=10; } if(n>0) printf("Repeatd digit(s):\n"); else printf("No repeated digit\n"); return 0; } 我的思路是设一个数组，把有重复的digit存入数组中，下标循环自加。但是首先你不知道会有多少个重复，所以数组的长度也定不了。。。。 另外实现的结果应为： Enter a number:939577 Repeated digit: 7 9
Rightmost Digit
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single positive integer N(1<=N<=1,000,000,000). Output For each test case, you should output the rightmost digit of N^N. Sample Input 2 3 4 Sample Output 7 6
Leftmost Digit 解决的办法
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single positive integer N(1<=N<=1,000,000,000). Output For each test case, you should output the leftmost digit of N^N. Sample Input 2 3 4 Sample Output 2 2
Last non-zero Digit in N! 编程的手段
Problem Description The expression N!, read as "N factorial," denotes the product of the first N positive integers, where N is nonnegative. So, for example, N N! 0 1 1 1 2 2 3 6 4 24 5 120 10 3628800 For this problem, you are to write a program that can compute the last non-zero digit of the factorial for N. For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce "2" because 5! = 120, and 2 is the last nonzero digit of 120. Input Input to the program is a series of nonnegative integers, each on its own line with no other letters, digits or spaces. For each integer N, you should read the value and compute the last nonzero digit of N!. Output For each integer input, the program should print exactly one line of output containing the single last non-zero digit of N!. Sample Input 1 2 26 125 3125 9999 Sample Output 1 2 4 8 2 8
Catch the Bus!
Problem Description ACM needs to deliver marketing materials to one of their clients. Both ACM and the client employ students to make such deliveries. And these students use public buses to move throughout the city. Sometimes, it is necessary to pass the materials as fast as possible. You are given bus timetables and your task is to find the fastest way for two students to meet at some stop. The place of the meeting is not important, they only need to meet as early as possible. Students may change between any two bus routes at stops that are common for both routes. At least two minutes are needed for every such change. No additional time is necessary to get on the first bus or to meet the other student in the target stop. Input The input contains a sequence of several scenarios, the sequence is terminated by a line containing negative number. Each scenario begins with a non-negative integer L, the number of bus routes that operate in the city (L ≤ 1000). Every route is then described by two lines. The first line contains names of stops that the bus runs through. Between each consecutive stops, there is a non-negative integer specifying the number of minutes required to travel between these stops with the given bus. The last stop is followed by a negative number. The second line of each bus route contains non-negative integers separated with spaces. The first integer H gives the number of buses that depart the initial stop in every hour (H ≤ 60). The remaining H integers are always distinct and sorted ascendingly, they list the minutes of departure (between 0 and 59). The timetable repeats every hour. For example, if the second line says “2 00 30”, the buses leave the initial stop at 12:00, 12:30, 13:00, 13:30, 14:00, etc. After the description of routes, there are two lines that specify the initial position of students. Each of them will contain time in a standard 24-hour format (one or two digits for hours, colon, and two digits for minutes) and a stop name. All numbers, times, and stop names will be separated with a single space. Stop names are case-sensitive and may be composed only from lower-case and upper-case letters, their length will not exceed 30 characters. The total number of stops will be at most 1000, the number of stops on a single route will not exceed 100. The time between any two consecutive stops will be at most one hour. The routes are considered one-way, if they operate in both directions, they will be given as two separate routes. A route may run through the same stop several times. Output For each test scenario, output a single line containing the earliest possible time the students can meet at any of the stops. The time must appear in the standard 24-hour format, hours given as a number between 0 and 23, then colon and minutes between 0 and 59. For hour values less than 10, only one digit must be used. Be aware of the fact that both students start their trip on the same day but may meet on another day, if the required time exceeds midnight. If the students are not able to meet in some scenario, output the words “No connection” instead of the time. Sample Input 4 Hradcanska 2 Malostranska 2 Staromestska 2 Mustek 1 Muzeum -1 10 00 06 12 18 24 30 36 42 48 54 Muzeum 1 Mustek 2 Staromestska 2 Malostranska 2 Hradcanska -1 10 03 09 15 21 27 33 39 45 51 57 Andel 2 Karlovo 1 Narodni 2 Mustek 2 Florenc -1 6 00 10 20 30 40 50 Florenc 2 Mustek 2 Narodni 3 Karlovo 1 Andel -1 6 02 12 22 32 42 52 12:00 Hradcanska 12:11 Andel 1 Hradcanska 2 Malostranska 2 Staromestska 2 Mustek 1 Muzeum 2 Hradcanska -1 10 00 06 12 18 24 30 36 42 48 54 12:00 Mustek 12:00 Andel -1 Sample Output 12:20 No connection
The Game of 31 游戏的算法
Problem Description The game of 31 was a favourite of con artists who rode the railroads in days of yore. The game is played with a deck of 24 cards: four labelled each of 1, 2, 3, 4, 5, 6. The cards in the deck are visible to both players, who alternately withdraw one card from the deck and place it on a pile. The object of the game is to be the last player to lay a card such that the sum of the cards in the pile does not exceed 31. Your task is to determine the eventual winner of a partially played game, assuming each player plays the remainder of the game using a perfect strategy. For example, in the following game player B wins: Player A plays 3 Player B plays 5 Player A plays 6 Player B plays 6 Player A plays 5 Player B plays 6 Input The input will consist of several lines; each line consists of a sequence of zero or more digits representing a partially completed game. The first digit is player A's move; the second player B's move; and so on. You are to complete the game using a perfect strategy for both players and to determine who wins. Output For each game, print a line consisting of the input, followed by a space, followed by A or B to indicate the eventual winner of the game. Sample Input 356656 35665 3566 111126666 552525 Sample Output 356656 B 35665 B 3566 A 111126666 A 552525 A

Problem Description If you hide some digits in an integer equation, you create a digit puzzle. The figure below shows two valid digit puzzles.Hidden digits are represented by squares, and other digits are shown. The numbers involved in this problem are all positive integers, written in decimal forms without leading zeros. If a digit puzzle has a unique solution, we call it a good puzzle. Both puzzles shown above are good puzzles. The solution to the first puzzle is 7*12=84, while the solution to the second one is 11*11=121. You are already given some digit puzzles, but some of them are not good. Your task is to convert these puzzles into good ones. You can change any wildcard character (i.e. hidden digits) into a real digit, any real digit to a wildcard character, or a real digit to another real digit, but you cannot insert or remove any character at any place. The number of changed characters should be minimized. In this problem, the puzzle is always in the form "a x b = c", and "a x b" and "b x a" should be considered different if a is not equal to b. It is allowed that all digits of both a and b are shown (e.g 12 x 34 = ****), though that puzzle is actually a simple multiplication problem. Write a program to make good puzzles. Input The input contains several test cases. Each test case contains three non-empty strings, x, y, z, having at most 2, 2 and 4 characters respectively. Each character is a digit or a wildcard '*', x will not begin with a zero character. The last test case is followed by a single zero, which should not be processed. Output For each test case, print the case number and the converted puzzle. If more than one optimal solution is found, the lexicographically first one should be printed (remember that "*" is before "0"). There is always a solution. Sample Input 7 ** 8* ** ** *** 0 Sample Output Case 1: 7 ** 8* Case 2: ** ** 1*1
Cover Up
Problem Description “The Price is Right” is a popular game show where contestants play various games to win fabulous prizes. One of the games played on the show is called “Cover Up” whose object is to guess a 5-digit number (actually, the price of a new car). In the actual game, contestants are given two numbers to choose from for the first digit, three numbers to choose from for the second digit, and so on. A contestant selects one number for each digit (from the set of yet unpicked numbers for that digit) and then is told which ones are correct; if at least one is correct, the player is allowed to guess again for all incorrect digits. The contestant keeps guessing as long as they keep getting at least one new digit correct. The game ends when either all the digits are correct (a win for the contestant) or after a turn when no new digit is guessed correctly (a loss). Typically this game is not sheer luck. For example, suppose you had the following five possibilities for the last digit: 1, 3, 5, 8 and 9. Many car prices end with either a 5 or a 9, so you might have, say, a 70% chance that one of these two numbers is correct; this breaks down to a 35% chance for either the 5 or the 9 and a 10% chance for each of the other three digits. Now say you pick the 5 and it’s wrong, but some other guess you made was right so you still get to play. With this additional information the probabilities for the remaining 4 numbers change: the probability for the 9 is now close to around 54%, while each of the other three numbers now has a little over a 15% chance. (We’ll let you figure out how we got these values). We’ll call the 5 and the 9 in the original group the known candidates, and typically there are known candidates in other columns as well. For example, if the two numbers for the first (high order) digit are 1 and 9, the contestant can be 100% sure that the 1 is the correct digit (there aren’t too many \$90,000 cars to be given away). For this problem, you are to determine the probability of winning the game if an optimal strategy for picking the numbers (based on probabilities such as those described above) is used. Input Each test case will consist of two lines. The first will be n, the number of digits in the number to be guessed. The maximum value of n will be 5. The second line will contain n triplets of numbers of the form m l p where m is the number of choices for a digit, l is the number of known candidates, and p is the probability that one of the known candidates is correct. In all cases 0 ≤ l < m ≤ 10 and 0.0 ≤ p ≤ 1.0. Whenever l = 0 (i.e., when there are no known candidates) p will always be 0.0. A line containing a single 0 will terminate the input. Output Output for each test case is the probability of winning using optimal strategy. All probabilities should be rounded to the nearest thousandth, and trailing 0’s should not be output. (A 100% chance of winning should be output as 1.) Sample Input 2 3 1 0.8 2 0 0.0 2 3 2 0.8 2 0 0.0 2 3 2 0.82 2 1 0.57 3 4 1 1.0 3 0 0.0 10 1 1.0 0 Sample Output 0.85 0.6 0.644 1
Digital Roots 的问题
Problem Description The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit. For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39. Input The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero. Output For each integer in the input, output its digital root on a separate line of the output. Sample Input 24 39 0 Sample Output 6 3
Count Problem 的编写
Problem Description In this problem,we need to count the number that accord with the following rule(include the input number n).Read a integer number n(1<=n<=2^31 - 1) first,then do as following ways: (1)Do nothing, then exit the process. (2)Add a digit to the left of it,but the digit should not bigger than the half of the original first digit.For example,from 36 to 136 is legal,but 36 to 236 is illegal because 2 is bigger than half of 3. (3)After add the digit,continue the process,until could not add digit anymore. Input The first line of the input contains an integer T which means the number of test cases.Then T lines follow, each line starts with a number n(1<=n<=2^31 - 1). Output For each test case, you should output one line contains the number that accord with the rule start from n. Sample Input 2 1 6 Sample Output 1 6
Problem Description An educational software company, All Computer Math (ACM), has a section on multiplication of integers. They want to display the calculations in the traditional grade school format, like the following computation of 432 × 5678: 432 5678 ------- 3456 3024 2592 2160 ------- 2452896 Note well that the final product is printed without any leading spaces, but that leading spaces are necessary on some of the other lines to maintain proper alignment. However, as per our regional rules, there should never be any lines with trailing white space. Note that the lines of dashes have length matching the final product. As a special case, when one of the digits of the second operand is a zero, it generates a single 0 in the partial answers, and the next partial result should be on the same line rather than the next line down. For example, consider the following product of 200001 × 90040: 200001 90040 ----------- 8000040 180000900 ----------- 18008090040 The rightmost digit of the second operand is a 0, causing a 0 to be placed in the rightmost column of the first partial product. However, rather than continue to a new line, the partial product of 4 × 200001 is placed on the same line as that 0. The third and fourth least-significant digits of the second operand are zeros, each resulting in a 0 in the second partial product on the same line as the result of 9 × 200001. As a final special case, if there is only one line in the partial answer, it constitutes a full answer, and so there is no need for computing a sum. For example, a computation of 246 × 70 would be formatted as 246 70 ----- 17220 Your job is to generate the solution displays. Input The input contains one or more data sets. Each data set consists of two positive integers on a line, designating the operands in the desired order. Neither number will have more than 6 digits, and neither will have leading zeros. After the last data set is a line containing only 0 0. Output For each data set, output a label line containing "Problem " with the number of the problem, followed by the complete multiplication problem in accordance with the format rules described above. Sample Input 432 5678 200001 90040 246 70 0 0 Sample Output Problem 1 432 5678 ------- 3456 3024 2592 2160 ------- 2452896 Problem 2 200001 90040 ----------- 8000040 180000900 ----------- 18008090040 Problem 3 246 70 ----- 17220
Escape 逃脱问题
Problem Description 2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets. Input More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet. The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most.. 0 <= ai <= 100000 Output Determine whether all people can live up to these stars If you can output YES, otherwise output NO. Sample Input 1 1 1 1 2 2 1 0 1 0 1 1 Sample Output YES NO
ISBN 的问题
Problem Description Farmer John's cows enjoy reading books, and FJ has discovered that his cows produce more milk when they read books of a somewhat intellectual nature. He decides to update the barn library to replace all of the cheap romance novels with textbooks on algorithms and mathematics. Unfortunately, a shipment of these new books has fallen in the mud and their ISBN numbers are now hard to read. An ISBN (International Standard Book Number) is a ten digit code that uniquely identifies a book. The first nine digits represent the book and the last digit is used to make sure the ISBN is correct. To verify that an ISBN number is correct, you calculate a sum that is 10 times the first digit plus 9 times the second digit plus 8 times the third digit ... all the way until you add 1 times the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN. For example 0201103311 is a valid ISBN, since 10*0 + 9*2 + 8*0 + 7*1 + 6*1 + 5*0 + 4*3 + 3*3 + 2*1 + 1*1 = 55. Each of the first nine digits can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit as X. For example, 156881111X is a valid ISBN number. Your task is to fill in the missing digit from a given ISBN number where the missing digit is represented as '?'. Input * Line 1: A single line with a ten digit ISBN number that contains '?' in a single position Output * Line 1: The missing digit (0..9 or X). Output -1 if there is no acceptable digit for the position marked '?' that gives a valid ISBN. Sample Input 15688?111X Sample Output 1
QR 的问题
Problem Description QR Codes (the smallest, which is 21 pixels by 21 pixels, is shown below) are square arrays of black or white pixels (modules) which include Position Detection Patterns (the square bull's-eye patterns), Timing Patterns (the alternating black and white lines), Alignment Patterns in larger QR Codes , Format Information (the stippled pixels), Version information in larger QR Codes and Data and Error Correction Codewords (gray 8 pixel blocks). The 21-by-21 QR Code has 26 data and error correction codewords. At the lowest error correction level for this code, 19 are data codewords and 7 are error correction codewords. Data may be encoded as numeric at 3 numbers per 10 bits, as alphanumeric at 2 characters per 11 bits, as 8 bit bytes or as Kanji at 13 bits per character. Data is encoded in groups of（mode,character count,character data bits）.The mode can change within the data stream. The mode is specified by a 4 bit code and the character count by a varying number of bits depending on the mode and QR Code size. For the 21-by-21 code, the character count bits are: The entire data stream ends in the termination code which may be truncated if there is not enough room. Any partially filled codeword after the termination code is filled with 0 bits. Any remaining codewords are set to 11101100 followed by 00010001 alternating. Numeric strings are encoded 3 digits at a time. If there are remaining digits, 2 digits are encoded in 7 bits or 1 digit in 4 bits. For example: 12345678 -> 123 456 78 -> 0001111011 0111001000 1001110 Prefix with mode (0001) and count (8 -> 0000001000) is (4 + 10 + 10 + 10 +7) bits: 0001 0000001000 0001111011 0111001000 1001110 Alphanumeric strings encode the haracters (<SP> represents the space character): 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<SP>\$%*+-./: as numbers from 0 to 44, then two characters are encoded in 11 bits: <first char code5> * 45 + <second char code> if the number of characters is odd, the last character is encoded in 6 bits. For example: AC-42 -> (10,12,41,4,2) -> 10*45+12=462, 41*45+4=1849, 2->00111001110 11100111001 000010 Prefix with mode and count is (4 + 9 + 11 + 11+ 6) bits: 0010 000000101 00111001110 11100111001 000010 The 8 bit binary and Kanji modes will be straightforward for the purposes of this problem. Kanji codes will just be opaque 13 bit codes; you need not decode the characters they represent, just the hexadecimal values. For example: 8 bit 0x45 0x92 0xa3 -> 01000101 10010010 10100011 Prefix with mode and count is (4 + 8 + 8 + 8 + 8) bits: 0100 00000011 01000101 10010010 10100011 Kanji 0x1ABC 07x0345 -> 1101010111100 0001101000101 Prefix with mode and count is (4 + 8 + 13 + 13) bits: 1000 00000010 1101010111100 0001101000101 To illustrate forming the 19 codeword content of a QR Code, combine the first 3 sequences above (for numeric, alphanumeric and bytes). Concatenate the bits, split into 8bit code words add the termination codeword, any fill bits and fill bytes (41 + 41 + 36 data bits + 4 bit termination code = 122 -> 6 fill bits are needed to get 16 bytes, and to fill out the 19 bytes, 3 fill bytes are needed): 0001 0000001000 0001111011 0111001000 1001110 0010 000000101 00111001110 11100111001 000010 0100 00000011 01000101 10010010 10100011 0000 000000 11101100 00010001 11101100 split into 8 bit codewords: 00010000 00100000 01111011 01110010 00100111 00010000 00010100 11100111 01110011 10010000 10010000 00001101 00010110 01001010 10001100 00000000 11101100 00010001 11101100 -> HEX 10207B72271014E77390900D164A8C0EC11EC Write a program to read 19 codewords and print the orresponding data. Input The first line of input contains a single integer P, (1 <= P <= 1000), which is the number of data sets that follow. Each data set is a single line of input consisting of the data set number, N, followed by a single space and 38 hexadecimal digits giving the 19 bytes of QR Code data. The valid hexadecimal digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F. Output For each data set there is one line of output. It contains the data set number (N) followed by a single space, the number of QR decoded characters in the result, a single space and the character string corresponding to the QR Code data. In the output string, printable ASCII characters (in the range 0x20 to 0x7e) are printed as the ASCII character EXCEPT that backslash (\) is printed as \\ and pound sign (#) is printed as \#. Non-printable 8 bit data is output as \xx, where x is a hexadecimal digit (e.g. \AE). Non-printable 8 bit data is any value that is less than the ASCII value of a space (0x20) or greater than 0x76. 13 bit Kanji values are printed as #bxxx, where b is 0 or 1 and x is a hexadecimal digit (e.g. #13AC). Sample Input 4 1 10207B72271014E77390900D164A8C00EC11EC 2 802D5E0D1400EC11EC11EC11EC11EC11EC11EC 3 20BB1AA65F9FD7DC0ED88C973E15EF533EB0EC 4 2010B110888D9428D937193B9CEA0D7F45DF68 Sample Output 1 16 12345678AC-42E\92\A3 2 2 #1ABC#0345 3 23 HTTP://WWW.ACMGNYR.ORG/ 4 36 3.1415926535897932384626433832795028

locker 如何来实现的
Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly. You can rotate 1-3 consecutive digits up or down in one step. For examples: 567890 -> 567901 (by rotating the last 3 digits up) 000000 -> 000900 (by rotating the 4th digit down) Given the current state and the secret password, what is the minimum amount of steps you have to rotate the locker in order to get from current state to the secret password? Input Multiple (less than 50) cases, process to EOF. For each case, two strings with equal length (≤ 1000) consists of only digits are given, representing the current state and the secret password, respectively. Output For each case, output one integer, the minimum amount of steps from the current state to the secret password. Sample Input 111111 222222 896521 183995 Sample Output 2 12
Generator 生成器的问题
Problem Description We can generate a random string by generating a sequence of random characters and concatenating them together. Each character is chosen independently from the first n letters in the English alphabet with equal probability. Only capital letters are used in this problem. The generation is stopped as soon as one of specific patterns occurs in the random string. Your task is to predict the expected length of the generated string. Input Standard input will contain multiple test cases. First line is the number of case x. Each test case consists of integer N (1<=N<=8) which is the number of letters used, and M (1<=M<=10) which is the number of patterns used. The following M lines contain the patterns which are non-empty strings consisting of letters chosen from the first N upper case English letters. The length of any pattern will not exceed 10. Output For each test case, print the expected length of the generated random string. All output numbers are rounded to the second digit after the decimal point. Sample Input 4 2 1 A 2 1 ABA 3 1 AAAAA 2 2 A AA Sample Output 2.00 10.00 363.00 2.00
Count Cross 交叉的计算
Problem Description Given a MM×NN grid with different colors(black and white) on each cell, your task is to calculate the total amount of crosses of black color. We say there exists a black cross centered at the black cell (x,y) if there are four positive integer L,R,U,D that the cell(x,y-L),(x,y+R),(x-U,y),(x+D,y) are all black. Note that if two crosses have the same center but different L,R,U,D, we consider they are distinct.We use 1 to describe black. For example 00100 00100 11111 00100 00100 00000 There are 16 black crosses. The MM and NN are large, so we divide the matrix into M×N rectangle blocks.If two cells are in the same block ,their colors are same. So we can divide the sample into 4×3 blocks. Input There are at most 100 cases. In every case,there are two integers, M, N in the first line. (1≤M, N≤50) The next line contains M positive integers which are less than or equals to 50. The p-th integer describe the p-th row block's height. The next line contains N positive integers which are less than or equals to 50. The p-th integer describe the p-th colomn block's width. The following M lines each has a string which contain N digits.The q-th digit in the p-th line describe the color of the q-th colomn block in the p-th row. Output Output the answer to each case. Sample Input 4 3 2 1 2 1 2 1 2 010 111 010 000 Sample Output 16
Alarm Clock 的问题求解
Problem Description Advanced courses in computer science often include many interesting optimization problems. The following optimization problem is not advanced, nor is it particularly interesting. You are to write a program to determine the minimum number of buttons a person must push to set their alarm clock. Assume the alarm clock has 7 buttons – hour-up, hour-down, tens-minute-up, and tens-minute-down, ones-minute-up, ones-minute-down, and am/pm. For example, continuously pushing the hour-up button will cause hour digit to go through the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, …. Pushing the hour-down button will cause the sequence to go in the reverse order. Pushing the tens-minute-up buttons cycles tens minute digit through the numbers 0, 1, 2, 3, 4, 5, 0, 1, … Pushing the ones-minute-up button cycles the one digit through the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, … Pushing the am/pm button causes toggles the am/pm indicator. Input The first line of input will contain an integer indicating the number of problems that need to be processed. Each line will contain two times – the first one the current time and the second one the desired time. All times will have the format: 1 or 2-digit hour; followed by a colon; followed by a 2-digit minute; followed by “am” or “pm”. A single space will separate the two times. Output Your program should produce one line of output for each problem using one of two formats: ”Going from 7:30am to 7:33am requires 3 pushes.” or “Going from 7:30am to 7:20am requires 1 push.” Sample Input 6 7:30am 7:30am 7:30am 7:33am 7:30am 7:20am 7:30am 7:27am 7:30am 7:30pm 7:10am 7:50am Sample Output Going from 7:30am to 7:30am requires 0 pushes. Going from 7:30am to 7:33am requires 3 pushes. Going from 7:30am to 7:20am requires 1 push. Going from 7:30am to 7:27am requires 4 pushes. Going from 7:30am to 7:30pm requires 1 push. Going from 7:10am to 7:50am requires 2 pushes.
Java学习的正确打开方式

linux系列之常用运维命令整理笔录

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。

Docker 技术发展为微服务落地提供了更加便利的环境，使用 Docker 部署 Spring Boot 其实非常简单，这篇文章我们就来简单学习下。首先构建一个简单的 S...

SQL-小白最佳入门sql查询一

redis分布式锁，面试官请随便问，我都会

Nginx 原理和架构
Nginx 是一个免费的，开源的，高性能的 HTTP 服务器和反向代理，以及 IMAP / POP3 代理服务器。Nginx 以其高性能，稳定性，丰富的功能，简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求，主要负责调度工作进程：加载配置、启动工作进程及非停升级。worker 进程负责处...
“狗屁不通文章生成器”登顶GitHub热榜，分分钟写出万字形式主义大作

《程序人生》系列-这个程序员只用了20行代码就拿了冠军

11月8日，由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办，科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。 　　区块链技术被认为是继蒸汽机、电力、互联网之后，下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力，电力解决了人类基本的生活需求，互联网彻底改变了信息传递的方式，区块链作为构造信任的技术有重要的价值。 　　1...
Java世界最常用的工具类库
Apache Commons Apache Commons有很多子项目 Google Guava 参考博客

【技巧总结】位运算装逼指南

Android 9.0 init 启动流程