Two digits in a string appear only once, and the rest are in pairs.

Source: Internet
Author: User

Two digits in a string appear only once, and the rest are in pairs.

Of course, if the problem is that there is only one different number, and other numbers are the same in pairs, then all numbers are exclusive or this number is obtained.

This time there are two numbers that appear only once, and the other numbers are the same

1) First, all numbers are different or the number t is obtained.

2) Calculate the position flag of the first 1 of the binary t.

3) divide all numbers into two groups (b1 [], b2 []) based on whether the binary flag position is 1 (the number of each group must be an odd number)

4) Group b1 and obtain ans1. group b2 and obtain ans2.

# Include
 
  
# Include
  
   
Using namespace std; # define isset (a, n) a & (1 <(n) # define N 1000int main () {int t, c, I, B [N], b1 [N], b2 [N], flag, cou1, cou2, ans1, ans2; while (cin> c, c) {if (c % 2! = 0) {cout <"c must be an even number" <
   
    
> B [0]; t = B [0]; for (I = 1; I
    
     
> B [I]; t ^ = B [I];} flag = 0; for (I = 0; I <32; I ++) if (isset (t, i) {flag = I; break;} cou1 = cou2 = 0; for (int I = 0; I
     
      

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.