08-30 hdu_steps1 hdu2095

Source: Internet
Author: User

Solve some problems in hdu_step 1


1.2.2 hdu_2095 find your present (2)


Enter the number of n, where the number appears an odd number, to find the number

At first, we thought that both hash and map can be used. However, there is a simpler method for this question, that is, exclusive or operation.

0 ^ 6 = 0 6 ^ 6 = 0 a number is different or after two times it is equal to no operation

In addition, after the input plug-in is used, the time is reduced from 500 ms + to 60 ms, and the effect is obvious.

#include <cstdio>using namespace std;inline void scan(int &x){char c;   while(c=getchar(), c<'0'||c>'9');  x=c-'0';  while(c=getchar(), c>='0'&&c<='9') x=x*10+c-'0';}int main(){int n;while(scanf("%d",&n),n){int tmp=0,x;for(int i=0;i<n;i++){scan(x);tmp^=x;}printf("%d\n",tmp);}}


Other questions in step 1 are very watery ..


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.