A1041 Be Unique (20 分)

First, the technical summary

  1. This question when thinking met, do not know how to process the input order problem, although there are a record number of times each, in turn, needs to appear again afterwards and appeared for the first time, and
    then we can actually use with another array to store the input sequence of characters, and then use another array number of occurrences of the record, so we can solve this problem.
  2. If the situation appears to run overtime use cin can use scanf, but this time I run the timeout did not occur.
  3. I put the following code
int number[N];
改成
int number[10010];

Then submit segmentation fault. I do not know why. . . . .

Second, the reference code:

#include<iostream>
using namespace std;
int hashTable[10010];
int main(){
    int N;
    cin >> N;
    int number[N];
    int index = -1;
    for(int i = 0; i < N; i++){
        cin >> number[i];
        hashTable[number[i]]++;
    }
    for(int i = 0; i < N; i++){
        if(hashTable[number[i]] == 1){
            index = number[i];
            break;
        }
    } 
    if(index == -1){
        cout << "None";
    }else{
        cout << index;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/tsruixi/p/11811200.html