iOS Interview Common questions

Source: Internet
Author: User

1. Jesus had 13 disciples, one of whom was the traitor who betrayed Jesus, please use the rule of exclusion to find the traitor: 13 people sitting around a circle, from the first person began to cycle off, count to three exclude, the last remaining person is a traitor

int people[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};

int count = 0;//is used to record a datagram

int number = 13;//Records alive

int i = 0;//record number of people are on the count.

while (number > 1) {

if (people[i]! = 0) {

count++; Assuming A[i] is not removed, the count is valid

} if (count = = 3) {

People[i] = 0;//removed,

Count = 0;//to clear Zero

number--;//number of survivors reduced by one

}

i++;//the next person to record the count.

if (i = = 13) {

i = 0;//when out of range, immediately set the number of numbers as the first person

}

} for (int i = 0; i < i++) {

if (People[i] > 0) {

printf ("Traitor is the first%d", People[i]);

}

}




2. There are 1 million numbers, each value range is 0~999999, to find out the number of repeated
#define COUNT 1000000

int main (void)
{
Inta[count] = {0};
for (int i = 0; i < COUNT; i++) {
int number = Arc4random ()%count;//random number as subscript, value as occurrence
A[number-1] + +;
    }
//output repeated numbers and repeated times
for (int i = 0; i < count;i++) {
if (A[i] > 1) {
printf ("%d repeats%d times\n", I+1,a[i]);
       }
    }
Return0;
}

iOS Interview Common questions

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.