IOS interview FAQ

Source: Internet
Author: User

IOS interview FAQ
1. jesus has 13 disciples, and one of them is the traitor who sold Jesus. Please use exclusion to find the traitor: 13 people sat around and started reporting cyclically from the first person and counted to three, the last person left is the traitor.

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

Int count = 0; // used to record the number of reports

Int number = 13; // record the number of living persons

Int I = 0; // records the number of persons reporting

While (number> 1 ){

If (people [I]! = 0 ){

Count ++; // If a [I] is not removed, the report count is valid.

} If (count = 3 ){

People [I] = 0; // remove,

Count = 0; // the return value is cleared.

Number --; // The number of active users minus one

}

I ++; // the next person in the record

If (I = 13 ){

I = 0; // set the number of applicants to the first when the value exceeds the specified range.

}

} For (int I = 0; I <13; I ++ ){

If (people [I]> 0 ){

Printf ("the traitor is % d", people [I]);

}

}




2. There are 1000000 numbers. The value range of each number is 0 ~ 999999. Find the number of duplicates.
# Derefined COUNT 1000000

Int main (void)
{
Inta [COUNT] = {0 };
For (int I = 0; I <COUNT; I ++ ){
Int number = arc4random () % COUNT; // use the random number as the subscript and the value as the number of occurrences
A [number-1] ++;
}
// Output repeated numbers and number of repetitions
For (int I = 0; I <COUNT; I ++ ){
If (a [I]> 1 ){
Printf ("% d repeats % d times \ n", I + 1, a [I]);
}
}
Return0;
}

Related Article

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.