2014 school recruitment --- Huawei machine examination questions Xiaohui (intermediate), 2014 Huawei

Source: Internet
Author: User


This article is based on CSDN-qingsong!

1. Reverse linked list output (test simulation)
Description:

Enter a one-way linked list and output the values of each node in reverse order.
The linked list node structure is defined as follows:
Typedef struct tagListNode
{
Int value;
Struct tagListNode * next;
} ListNode;

Running time limit: 60 Sec
Memory limit 256 MByte
Input:


Sequentially enter the nodes of the linked list, and use commas (,) as the separator of the node data;
For example: Linked List 1-> 2-> 3-> 4-> 5, input: ", 5"


Output:


Each node of the list in reverse order, using comma (",") as the separator of the node data;
For example, 5-> 4-> 3-> 2-> 1 after the reverse order of the linked list, the output is: "5, 4, 3, 2, 1"


Sample input: 1, 2, 3, 4, 5
Sample output: 5, 4, 3, 2, 1

Programming Logic: Traverse the original linked list and record each node: record the previous traversal node (that is, its precursor node, which requires extra space), the current node, and the successor of the current node; changes the source node of the current node to its successor node, and the successor node of the current node to a new current node. It is specially processed for the first and last nodes of the linked list.
Code Implementation:
# Include <stdio. h> # include <stdlib. h> // chain table node Structure typedef struct tagListNode {int value; struct tagListNode * next; // subsequent node pointer} ListNode; // create a new chain table node // parameter ppstNode, pointer to the new node pointer // parameter nValue, value of the new node (in integer form) void new_node_create (ListNode ** ppstNode, int nValue) {* ppstNode = (ListNode *) malloc (sizeof (ListNode); (* ppstNode)-> value = nValue; (* ppstNode)-> next = NULL ;} // create a new linked list node and append it to the end of the specified linked list // The ppstTail parameter points to the last node pointer of the linked list Pointer // parameter pValue, value of the new node (string form) void new_node_append (ListNode ** ppstTail, char * pValue) {ListNode * pstNow; new_node_create (& pstNow, atoi (pValue); (* ppstTail)-> next = pstNow; * ppstTail = pstNow;} // create a linked list based on the standard input. // The parameter ppstTail, void list_create (ListNode ** ppstHead) {ListNode * pstTail; char szInput [100]; char * p; int I; // read standard input scanf ("% s", szInput); // create a linked list pstTail = * ppstHead; p = SzInput; for (I = 0; szInput [I]! = '\ 0'; I ++) {if (szInput [I] =', ') {szInput [I] =' \ 0'; // create a new node, and add it to the end of the linked list new_node_append (& pstTail, p); p = szInput + I + 1 ;}} // process new_node_append (& pstTail, p) ;}// reverse linked list // The parameter ppstTail, void list_reverse (ListNode ** ppstHead) {ListNode * pstNow, * pstPrev, * pstNext; // The current node, the precursor node, and the successor node pstNow = (* ppstHead)-> next; // the current node is initialized as the first node pstPrev = * ppstHead of the single-chain table; // initialize the precursor node as the header node while (pstNow! = NULL) {// Save the successor node pstNext = pstNow-> next of the current node; if (pstPrev = * ppstHead) pstNow-> next = NULL; // The successor pointer of the first node of the original single linked list is empty after the reset. else pstNow-> next = pstPrev; // The precursor node of other nodes of the original single linked list is changed to its successor node pstPrev = pstNow; // The precursor node of the next node is the current node pstNow = pstNext; // The next node is changed to the current node} (* ppstHead)-> next = pstPrev; // The Last node of the original single linked list is changed to the first node after reverse configuration, that is, the successor node of the head node} // The linked list element traverses print // The ppstTail parameter, and the pointer to the head node of the linked list is void list_print (ListNode ** ppstHead) {ListNode * pstNow; pst Now = (* ppstHead)-> next; while (pstNow-> next! = NULL) {printf ("% d,", pstNow-> value); pstNow = pstNow-> next;} printf ("% d", pstNow-> value ); // The end of the last node contains a comma.} // release the linked list // The ppstTail parameter. The pointer to the head node of the linked list is void list_free (ListNode ** ppstHead) {ListNode * pstNow, * pstNext; pstNow = (* ppstHead)-> next; while (pstNow! = NULL) {pstNext = pstNow-> next; free (pstNow); pstNow = pstNext ;}} int main (void) {ListNode * pstHead; // create the header node new_node_create (& pstHead, 0); // create the list_create (& pstHead) linked list based on the standard input; // printf ("After create :"); // delete or comment out the debugging output during submission. // list_print (& pstHead ); // delete or comment out the debugging output during submission. // The list_reverse (& pstHead) of the linked list is reversed. // printf ("\ nAfter reverse :"); // delete or comment out the debugging output when submitting the request. list_print (& pstHead); // release list_free (& pstHead); return 0 ;}

2. Be considerate


Description:

At a dating scene, n (1 ≤ n ≤ 500) was an interesting game for both men and women: the host draws a grid (2n in total) on the ground. Each grid contains an integer Ai (1 ≤ Ai ≤ 500 ). After the game starts, let them stand in a row at Will (maybe two people are standing in the same grid ). After they all stood up, the Division started to calculate the scores of each of them. The scoring rule is: The score of the male is equal to that of the starting point of the station, the female's score is equal to the sum from the position where she stood to the end. If a pair of men and women have the same scores, they have a high level of tacit understanding, a strong relationship, and a high success rate of dating. For example, there are three men and women. The numbers in the row on the ground are: 3, 6, 2, 4, 5, and 2. If the male is in the third position (2), his score is: 3 + 6 + 2 = 11; the female is in the third position (4 ), her score is 4 + 5 + 2 = 11. If the two share the same score, they think they have a tacit understanding. Or the male station has 6th positions (2) and the female station has 1st positions (3), and their scores are equal to 22. If your friend is on the show, so please help him/her calculate the number of station methods to quickly find the tacit understanding of her/him (if the parameter is invalid, return-1 ).

Running time limit: Unlimited
Memory limit Unlimited
Input:

The first line is an integer n, which represents the logarithm of a good man's letter.

The second row contains a batch of integers N, representing the numbers on the ground. NOTE: If N is not equal to 2 * n, the output is-1.

Output:

There are several methods for output.

The input data is invalid. Output-1.

Sample input: 3
3 6 2 4 5 2
Sample output: 2



Programming Logic: What I understand is a tacit understanding of men and women. According to the question, both the male and the female may appear in any of the 2n grids. Calculate the score of a man or a woman in any of the 2n grids, and then use a dual loop, the outer loop traverses the 2n possible positions of the male, and the inner loop traverses the 2n possible positions of the female. When both male and female share the same score, the possible method of counting and adding one.
Code Implementation:
# Include <stdio. h> # include <stdlib. h> # include <string. h> # define LATTICE_MAX_NUM 1000 // calculate the score int score_calc_man (int * pLatticeList, int nPos) for a man standing on a grid {int I, nScore = 0; for (I = 0; I <= nPos; I ++) nScore = nScore + = pLatticeList [I]; return nScore ;} // calculate the score int score_calc_lady (int * pLatticeList, int nPos, int nListSzie) {int I, nScore = 0; for (I = nPos; I <nListSzie; I ++) nScore = nScore + = pLatticeList [I]; return nScore;} // count int privity_calc (int * pLatticeList, int nListSzie) {int nManScoreList [LATTICE_MAX_NUM]; // when the male is in any of the 2n grids, his score is int nLadyScoreList [LATTICE_MAX_NUM]; // when the female is in any of the 2n grids, her score is int I, j, nCount = 0; for (I = 0; I <nListSzie; I ++) {nManScoreList [I] = score_calc_man (pLatticeList, I ); nLadyScoreList [I] = score_calc_lady (pLatticeList, I, nListSzie) ;}for (I = 0; I <nListSzie; I ++ ){ For (j = 0; j <nListSzie; j ++) {if (nLadyScoreList [j] = nManScoreList [I]) nCount ++ ;}} return nCount ;} int main (void) {int nCoupleCount; // how many pairs of Men and Women int nLatticeList [LATTICE_MAX_NUM]; // The value int nListSzie = 0 in the grid; // how many lattice int I, nTemp; char szInput [4096]; char * pTemp; // reads the male logarithm scanf ("% d", & nCoupleCount); if (nCoupleCount <1 | nCoupleCount> 500) // Determination of input validity, 1 ≤ n ≤ 500 {printf ("% d",-1); return-1 ;}// read the value fflush (stdin) in the grid );/ /Be sure to clear the input buffer; otherwise, the fgets and gets will directly obtain the line break left by the previous scanf, instead of waiting for the input fgets (szInput, sizeof (szInput), stdin ); // danger of overflow when using gets (szInput) pTemp = szInput; nListSzie = 0; for (I = 0; szInput [I]! = '\ 0'; I ++) {if (szInput [I] = '') {szInput [I] =' \ 0'; nTemp = atoi (pTemp ); if (nTemp <1 | nTemp> 500) // determines the validity of the input, 1 ≤ Ai ≤ 500 {printf ("% d",-1); return-1 ;} nLatticeList [nListSzie ++] = nTemp; pTemp = szInput + I + 1 ;}} nTemp = atoi (pTemp); if (nTemp <1 | nTemp> 500) // Determination of input validity, 1 ≤ Ai ≤ 500 {printf ("% d",-1); return-1;} nLatticeList [nListSzie ++] = nTemp; if (nListSzie! = NCoupleCount * 2) // determines the validity of input. N equals 2 * n {printf ("% d",-1); return-1;} printf ("% d ", privity_calc (nLatticeList, nListSzie); return 0 ;}




3. Cave escape
Description:

Prince jingling is adventurous. During his adventure, he entered a mysterious cave. In the depths of the cave, the ghost Prince accidentally touched the hidden organs in the cave. The whole cave will soon collapse, and the ghost prince must flee the cave as soon as possible. Prince Ling's running speed is 17 m/s, so he may not be able to escape from the cave at this speed. Fortunately, the ghost prince has a flashing spell that can be moved 60 m within 1 s, but each time he uses a flashing spell, the magic value will be 10 points. The magic value of the ghost prince can be restored at a speed of 4 o'clock/s, and can be recovered only when he is resting in the same place.
It is now known that the magic initial value of the spirit Prince M, the distance between his location in the cave and the exit of the cave S, the time T from the collapse of the cave.

Your task is to write a program to help the genie Prince calculate how to escape from the cave in the shortest time. If you can escape, output "Yes", and output the shortest time used to escape; if you cannot escape, output "No", and output the shortest distance that the ghost prince can go in the remaining time. Note the case sensitivity. Note: The running, blinking, or resting activities are measured in seconds. The duration of each activity is an integer second. The distance is measured in meters (m ).
Note: M, S, and T are integers greater than or equal to 0. The validity of the value is ensured by the input, and the examinee does not need to check the value.
Reminder:
If the input S is 0, it indicates that it is already at the exit and the output should be: Yes 0
If the input T is 0 (and S is not 0), it indicates that there is No time, and the output should be: No 0

Running time limit: Unlimited
Memory limit Unlimited
Input:


M
S
T


Output:


Yes, the shortest time for escaping from the cave
Or
No. The longest distance to escape before the cave collapse


Sample input: 10
50
5
Sample output: Yes 1

Programming Logic: Greedy. You can choose the farthest distance for every second. So we use two methods each time to move forward, and finally choose the method that can go the farthest.
Code Implementation: See http://blog.csdn.net/xiaozhuaixifu/article/details/25302069
Error Message
What are the recruitment information of Shenzhen Huawei group in May 2014?

Currently, Huawei does not recruit formal employees. Only the optoelectronic division is recruiting smt r & D personnel (dispatched workers, no Provident Fund). As long as it is a master student, you can apply for an employee. However, there is no overtime fee for working overtime, you need to understand this. Other projects, including the investment management department and overseas operation department, have already been laid off. On last Thursday, our Investment Management Committee also received a notification to HUAWEI 3COM (BVI), an overseas company of HUAWEI) CORP will conduct a capital chain review. If there is a problem with the review, the overseas company will close, directly affecting Huawei's recruitment progress.
 

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.