Common algorithmic topics in iOS interviews

Source: Internet
Author: User

First, preface

Here is the iOS job in the problem of the algorithm, I hope to help you. Not regularly updated. If you want to run code debugging online, you can copy the code here. and then Debug. The following are common algorithm topics.

Second, the text

1, on the factorial of N.

Idea: This is achieved by recursion

#include <stdio.h>intGETNJ (intN) {if(n==1|| n==0) {        return 1; }    returnN*GETNJ (n1);}intMain () {printf ("%d", Getnj (Ten)); return 0;}

The results of the operation are as follows:

3628800

2, determine whether a string is an IP.

Idea: First divide the string into two arrays (a numeric array, a character array), and then determine whether the content of the array satisfies the IP condition, and whether the character array is ".". This mainly uses the SSCANF function. The code is as follows:

#include <stdio.h>intCheckip (Const Char*p) {intn[4]; Charc[4]; if(SSCANF (P,"%d%c%d%c%d%c%d%c", &n[0],&c[0],&n[1],&c[1],&n[2],&c[2],&n[3],&c[3])==7) {        inti;  for(i=0;i<3; i++) {            if(c[i]!='.') {                return 0; }            }         for(i=0;i<4; i++) {            if(n[i]>255|| n[i]<0) {                return 0; }        }        return 1; }Else {        return 0; }}intMain () {Const Char*x[] =     {        "132.168.1.1",        "10.0.0.1.",        "127.256.0.1",        "Iudfdsfdasfdaf",        "172.16,2.1"    }; Const Char*m[] =     {        "not a legitimate IP address",         "It's a legitimate IP address."    }; intI=0;  while(x[i]!=0) {printf ("%s%s\n", X[i],m[checkip (X[i])); I++; }    return 0; return 0;}

The results of the operation are as follows:

132.168. 1.1 It's a legitimate IP address. 10.0. 0.1 . Not a valid IP address 127.256. 0.1 not a valid IP address IUDFDSFDASFDAF is not a valid IP address 172.16,2.1 is not a legitimate IP address

Common algorithmic topics in iOS interviews

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.