明明的随机数 python、C++ 审核通过

T001 2024-09-07 13:17:10 7

C++: //做法1 #include <bits/stdc++.h> using namespace std;

int main() { int n, t, a[1005] = { 0 }, cnt = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> t; if (a[t] == 0) { a[t] = 1; cnt++; } } cout << cnt << endl; for (int i = 1; i <= 1000; i++) { if (a[i] == 1) cout << i << " "; } return 0; } //做法2 //做法2 #include<bits/stdc++.h> using namespace std;

int main(){ sets; int n,a[105]; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; s.insert(a[i]); } cout << s.size() << endl; while(!s.empty()){ cout << *s.begin() << " "; s.erase(s.begin()); } return 0; } python(精锐): #python n = int(input()) nums = sorted(list(set(list(map(int, input().split())))))

print(len(nums)) print(" ".join(str(i) for i in nums))

{{ vote && vote.total.up }}