Nastya and an Array
输出有几种不同的数字
#pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JUDGE #include "stdafx.h" #else #include<bits/stdc++.h> #endif using namespace std; typedef long long lint; typedef vector<int> VI; typedef pair<int, int> PII; typedef queue<int> QI; typedef map<int, int> MII; void makedata() { freopen("input.txt", "w", stdout); fclose(stdout); } int p[150000], q[150000]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif //makedata(); std::ios::sync_with_stdio(0), cin.tie(0); int n, x; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { cin >> x; if (x > 0) { if (!p[x]) ans++; p[x] = true; } if (x < 0) { if (!q[-x]) ans++; q[-x] = true; } } cout << ans << endl; return 0; }