Topic: Write a function, check a string is not a valid IP address, the legal format should be as: 192.168.0.1 function: int is_valid_ip (char * s_ip); return value: 0: NOT IP 1: IS IP
At the same time, write a test code to test your function.
my answer:
INT IS_VALID_IP (CHAR * SIP) {INT RET = 1; INT IP [4] = {0,}; char TMP [2] = 0; int Num = SSCANF (SIP, "% d.% d.% d.% D% 1S ", & IP [0], & IP [1], & IP [2], & IP [3], TMP); if (Num == 4) {for (INT i = 0; i <4; i ) { IF (ip [i] <0 || ip [i]> 255) {RET = 0; Break;}}} else {RET = 0;} Return Ret;
Today, I will go to the interview. The questions of the MFC have not been done, doing the questions, in general, the relatively failed.
1. Decomposition equation: a * x * x b * x cint quadratic (Double A, Double B, Double C, Double & X1, Double & x2); Return Value: Solution
2. The maximum number of conventions DWORD Divisor (DWRD DWFirst, DWORD DWSECOND); Return Value: Maximum Covenant
3. Calculate the circumferential rate Double Pi (DowrD dwcount / * test number * /) according to Monte Carlo Algorithm; Return Value: Pi
4. No symbolic integer multiplication, multiplier is 32bit, resulting in 64bit Tips: 32bit integer decomposing to 16bit multiplied Void Multiply (DWORD DWFIRST, DWORD & DWLOWER);
5. Link list (from a small to large) node is defined as: struct node {int nvalue; struct node * pnext;}; PNEXT = null.struct node * sortchain (struct node * phead); return value: Link watch header
answer:
1. Int quadratic (Double A, Double B, Double C, Double & x1, Double & x2) {int RET = 0; Double E = 0.000000001; IF (a == 0) {if (b == 0) {RET = 0 } Else {RET = 1; x1 = -c / b;}} else {double b = b * b; double c = 4.0 * a * c; if (b 3. Double Pi (Dowrd Dwcount / * Tests * /) {Double R = 32767.0; DWORD Count = 0; SRAND (NULL)); // This code did not write, because there is no MSDN, only Remember a RAND (), and even 32767 is also tried. For (DWORD I = 0; I 4.void Multiply (DWORD dwFirst, DWORD dwSecond, DWORD & dwHigh, DWORD & dwLower) {DWORD ah, al, bh, bl ah = dwFirst >> 16; al = dwFirst & 0xffff; bh = dwSecond >> 16; bl = dwSecond & 0xffff; dwHigh = AH * BH; DWLOWER = Al * BL; DWORD TMP1 = AH * BL; DWORD TMP2 = Al * BH; DWHIGH = TMP1 >> 16; DWHigh = TMP2 >> 16; DWORD TMP3 = (TMP1 & 0xFFFF) (TMP2 & 0xFFFF) (dwlower >> 16); dwhigh = TMP3 >> 16; dwlower & = 0xfff; dwlower | = (TMP3 & 0xFFFF) << 16;} 5. // Method 2: Sampling Struct Node * Sortchain (Struct Node * PHEAD) {DWORD DWNUM == 0; if (PHEAD = NULL) {Return Null;} node * pChain = PHEAD; dwnum = 1; While (PChain- > pnext! = null) {dwnum ; pChain = pChain-> pnext;} for (DWORD i = 0; i @ Method 2: insertion sort struct Node * NewSortChain (struct Node * pHead) {struct Node * pNewHead = NULL; // list newly constructed struct Node * pOldChain = NULL; // for traversing the old list struct Node * pOldChainNext = NULL; / / PNEXT for temporarily storeing Poldchain Poldchain = PHEAD;