Sometimes I will take some questions about the basic ability to exercise. The following examples are used for simple analysis.
1. IP AddressDescriptionsuppose you are reading byte streams from any device, representing IP addresses. your task is to convert a 32 characters long sequence of '1s 'and '0s' (BITs) to a dotted decimal format. A dotted decimal format for an IP address is form by grouping 8 bits at a time and converting the binary representation to decimal representation. any 8 bits is a valid part of an IP address. to convert Binary numbers to decimal numbers remember that both are positional numerical systems, where the first 8 positions of the binary systems are: 27 26 25 24 23 22 21 20128 64 32 16 8 4 2 1 inputthe input will have a number N (1 <= n <= 9) in its first line representing the number of streams to convert. n lines will follow. outputthe output must have n lines with a doted decimal IP address. A dotted decim Al IP address is formed by grouping 8 bit at the time and converting the binary representation to decimal representation. sample input40000000000000000000000000000 00000011100000001111111111111111 11001011100001001110010110000000 01010000000100000000000000000001 sample output0.0.0.03.128.255.255203.132.229.12880.16.0.1 Translation: The 23-bit 0/1 sequence can be used to represent an IP address. The question requires converting the given 32-bit sequence into an IP address. For example, sequence 00000011100000001111111111111111 can be converted to 3.128.20.255. Solution: divide the sequence into eight groups, convert the binary sequence to the decimal number, and then connect the four numbers. The question is relatively simple and no reference code is provided.
2,ElevatorDescription of 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 Fu Lfill 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. enter There are multiple test cases. each case contains a positive integer N, followed by n positive numbers. all the numbers in the input are less than 100. A test case with n = 0 denotes the end of input. this test case is not to be Process Ed. print the total time on a single line for each test case. example input 1 23 2 3 10 example output 1741. It takes 6 seconds for the elevator to go up the next layer, 4 seconds for the next layer, and 5 seconds for each layer. The question must be based on the given request sequence to find the time required for the elevator to complete all tasks. The elevator was at the beginning on The 0th floor. Solution: Use sum to indicate the total time. The initial value is 0. For each request sequence, retrieve the floor of each request. If it is the first in the request sequence, calculate the time required for going upstairs (N * 6 ), plus the elevator stop time (5), sum = sum + N * 6 + 5. If it is not the first request, check the last request location M. If it is smaller than the current location, calculate the upstairs time (n-m) * 6, the elevator stay time 5, sum = sum + (n-m) * 6 + 5. If the value is greater than the current position, calculate the next floor time (m-N) * 4, and the elevator stop time is 5, sum = sum + (m-N) * 4 + 5. The reference code is as follows:/** elevator running time */public static void test4 (INT [] datas) {// It indicates that the original floor int m = 0; // indicates the total time int sum = 0; For (INT I = 1; I <= datas [0]; I ++) {int n = datas [I]; if (n> m) {sum = sum + (n-m) * 6 + 5;} else {sum = sum + (m-N) * 4 + 5 ;} M = N;} system. out. println (SUM );}
3. subtraction of a setSubtraction of the Problem description set. (Of course, we all know the definition of a set, that is, there will not be two identical elements in the same set. Here we will remind you ). Each input group occupies one row. Each row starts with two integers, n (0 <n <= 100) and M (0 <m <= 100 ), indicates the number of elements of set a and Set B respectively, followed by N + M elements. The first n elements belong to set a, and the rest belong to Set B. each element is an integer not greater than the int value range. Each element is separated by a space. if n = 0 and m = 0, the input ends without processing. Output outputs a line of data for each group of data, indicating the results of the A-B, if the results are empty set, the output "null", otherwise the output results from small to large, to simplify the problem, each element is followed by a space. sample input3 3 1 2 1 1 4 73 7 2 5 8 2 3 4 5 6 7 8 0 0 sample output2 3 null solution: no difficulty, is the basic skill of exercise. Obtain a set and B from each test case, traverse all elements in a set, and output this element if it is not in B set. No reference code is provided.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service