Huazhong University of Science and Technology's 10-year computer postgraduate Review

Source: Internet
Author: User

Question 1:

Three questions in total, 1.5 hours, C language implementation. Time is tight ....

 

A. Enter a string, perform odd verification on each character, and output the verified binary number! (For example, '3', output: 10110011 );

B. Design eight task functions task0 ()-task7 () to output only one sentence: for example, task0 () to output "task0 is called !"; Design a scheduling function schedule () to input a string such as "012345" and then return a function pointer array and the length of the string as the parameter for executing the execute () function to schedule the task. The main function only has scheduling functions.

C. Implement a multiplier to ensure that the two integers are any long integers.

 

Reference Program:

A,

# Include <stdio. h> <br/> # include <stdlib. h> <br/> int F (int n) {<br/> int C; <br/> for (C = 0; n! = 0; C ++) <br/> N = N & (n-1); <br/> return C; <br/>}< br/> int main () {<br/> char STR [1, 1000]; <br/> for (; scanf ("% s", STR )! = EOF;) {<br/> for (INT I = 0; STR [I]; I ++) {<br/> int X = F (STR [I]); <br/> printf ("% d", X & 1? 0: 1); <br/> for (Int J = 6; j> = 0; j --) {<br/> printf ("% d ", (STR [I]> J) & 1); <br/>}< br/> system ("pause "); <br/>}< br/> 

Data test:

B. It is for reference only...

# Include <stdio. h> <br/> # include <string. h> <br/> # include <stdlib. h> <br/> typedef void (* ptask) (); <br/> // 8 Task functions; <br/> void task0 () {<br/> printf ("task0 is called! /N "); <br/>}< br/> void task1 () {<br/> printf (" task1 is called! /N "); <br/>}< br/> void task2 () {<br/> printf (" task2 is called! /N "); <br/>}< br/> void task3 () {<br/> printf (" task3 is called! /N "); <br/>}< br/> void task4 () {<br/> printf (" task4 is called! /N "); <br/>}< br/> void task5 () {<br/> printf (" task5 is called! /N "); <br/>}< br/> void task6 () {<br/> printf (" task6 is called! /N "); <br/>}< br/> void task7 () {<br/> printf (" task7 is called! /N "); <br/>}< br/> ptask fun [9] = {task0, task1, task2, task3, task4, task5, task6, task7 }; </P> <p> void execute (ptask * Fun, int Len) {// execute the function <br/> for (INT I = 0; I <Len; I ++) {<br/> ptask pfun = fun [I]; <br/> pfun (); <br/>}</P> <p> void schedule () {// scheduling function; <br/> ptask fun [100]; // define the function pointer array; <br/> int Len; // String Length; <br/> char s [1000]; <br/> printf ("enter a string: /n "); <br/> scanf (" % s ", S); <br/> Len = strlen (s ); <br/> for (INT I = 0; I <Len; I ++) {<br/> int temp; <br/> temp = s [I]-'0'; <br/> If (temp = 0) Fun [I] = task0; <br/> else if (temp = 1) Fun [I] = task1; <br/> else if (temp = 2) Fun [I] = task2; <br/> else if (temp = 3) Fun [I] = task3; <br/> else if (temp = 4) Fun [I] = task4; <br/> else if (temp = 5) Fun [I] = task5; <br/> else if (temp = 6) Fun [I] = task6; <br/> else if (temp = 7) Fun [I] = task7; <br/>}< br/> execute (fun, Len ); <br/>}</P> <p> int main () {<br/> schedule (); <br/> system ("pause "); <br/>}< br/>

Data test:

C,

# Include <iostream> <br/> # include <string> <br/> using namespace STD; <br/> string addition (string one, string two ); <br/> int main () <br/> {<br/> int N, I; <br/> string first, second; <br/> cout <"Please enter two numbers:"; <br/> CIN> first> second; <br/> cout <"the result is: "<addition (first, second) <Endl; <br/> // return 0; <br/> system (" pause "); <br/>}< br/> string addition (string one, string two) <br/>{< br/> Int J, Max; <br/> // represents the length of the first and second strings respectively <br/> int FLEN, slen; <br/> string sum; <br/> FLEN = one. size (); <br/> slen = two. size (); <br/> If (FLEN> = slen) <br/>{< br/> sum = one; <br/> for (j = 0; j <slen; j ++) <br/> sum [flen-j-1] = sum [flen-j-1] + two [slen-j-1]-'0'; <br/> max = FLEN; <br/>}< br/> else <br/> {<br/> sum = two; <br/> for (j = 0; j <FLEN; j ++) <br/> sum [slen-j-1] = sum [slen-j-1] + one [flen-j-1]-'0'; <br/> max = slen; <br/>}< br/> // if the number of the J-digit is greater than 9, subtract 10 from it, and forward to the previous one <br/> for (j = max-1; j> = 1; j --) <br/>{< br/> If (sum [J]> '9') <br/>{< br/> sum [J]-= 10; <br/> sum [J-1] + +; <br/>}< br/> If (sum [0]> '9 ') <br/>{< br/> sum [0]-= 10; <br/> sum = "1" + sum; <br/>}< br/> return sum; <br/>}< br/> 

Data test:

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.