371 条题解
-
0chengchunyang LV 10 @ 2020-06-05 11:33:38
#include <cstdio> #include <iostream> using namespace std; int n,cnt = 0; bool bo[1001]; int main(){ cin >> n; for (int i = 1;i <= n;i++){ int x; cin >> x; if (bo[x]==false){ bo[x] = true; cnt++; } } cout<<cnt<<endl; for (int i = 1;i <= n;i++){ if (bo[i]){ cout<<i<<" "; } } reuturn 0; }
-
02020-06-05 11:33:38@
#include <cstdio> #include <iostream> using namespace std; int n,cnt = 0; bool bo[1001]; int main(){ cin >> n; for (int i = 1;i <= n;i++){ int x; cin >> x; if (bo[x]==false){ bo[x] = true; cnt++; } } cout<<cnt<<endl; for (int i = 1;i <= n;i++){ if (bo[i]){ cout<<i<<" "; } } reuturn 0; }
-
02020-05-09 13:35:03@
大水,模拟
#include<iostream> using namespace std; int main(){ int n,x,sum=0,bus[1002]={}; cin>>n; for(int i=1;i<=n;i++){ cin>>x; if(bus[x])continue; bus[x]++;sum++; } cout<<sum<<endl; for(int i=1;i<=1000;i++)if(bus[i])cout<<i<<" "; cout<<endl; return 0; }
-
02020-03-18 00:42:46@
set大法好
#include<iostream> #include<set> using namespace std; set<int> s; int main(){ int n, tmp; cin >> n; for(int i = 0 ; i < n ; ++i) { cin >> tmp; s.insert(tmp); } cout << s.size() << endl; for(auto iter = s.begin(); iter != s.end(); ++iter) { cout << *iter << " "; } cout << endl; return 0; }
-
02020-02-08 17:30:14@
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { int amount; cin>>amount; vector <int> array; for(int i=0;i<amount;i++) { int number; cin>>number; array.push_back(number); if(i!=0) for(int j=0;j<array.size()-1;j++) if(array[j]==array[array.size()-1]) { array.pop_back(); break; } } cout<<array.size()<<endl; sort(array.begin(), array.end()); for(int i=0;i<array.size();i++) cout<<array[i]<<" "; }
-
02019-07-21 14:42:39@
不是直接用set就过了吗哈哈哈
#include <iostream> #include <algorithm> #include <cstring> #include <set> using namespace std; set<int> store; int main() { int n, temp; cin >> n; for(int i=0; i<n; i++){ cin >> temp; store.insert(temp); } cout << store.size() << endl; set<int>::iterator it; for(it = store.begin(); it!=store.end(); it++){ cout << *it << " "; } return 0; }
-
02019-06-18 08:40:38@
#include <iostream>
using namespace std;
int main(void)
{
int n, a[100] = { 0 };
int b[100] = { 0 };
int j = 0, t = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i - j];
for (int k = 0; k < i-j; ++k) {
if (a[i-j] == a[k]) {
a[i - j] = 0;
++j;
break;
}
}
}
cout << n - j << endl;
for (int k = 0; k < n - j; ++k) {
for (int i = 0; i < n-j; ++i) {
if (a[t] > a[i])t = i;
}
b[k] = a[t];
a[t] = 2147483647;
}
for (int i = 0; i < n - j; ++i)cout << b[i] << ' ';
return 0;
} -
02019-05-26 23:43:47@
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a[120],i,k,x,j; bool f[1100]; int comp(int a,int b) { if(a<b) return 1; else return 0; } int main() { memset(f,0,sizeof(f)); scanf("%d",&n); j=0; for(i=1;i<=n;i++) { scanf("%d",&x); if(f[x]==1) continue; if(f[x]==0) { j++; a[j]=x; f[x]=1; k++; } } sort(a+1,a+k+1,comp); cout<<k<<endl; for(i=1;i<=k;i++) cout<<a[i]<<' '; return 0; }
-
02019-02-27 22:12:54@
#include<iostream>
#include<list>
using namespace std ;
int main()
{
list<int>v;
list<int>::iterator start,end;
int n,t;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>t;
v.push_back(t);
}
v.sort();
v.unique();
cout <<v.size() <<endl ;
for(start = v.begin(),end =v.end() ;start!=end;start++)
{
cout << *start <<" ";
}
return 0;
} -
02019-02-18 12:24:48@
/**
*使用快排进行排序然后替换所有重复的值,统计重复数量,进行输出。
*/
import java.util.Scanner;public class Main {
static int[] a;
public static void f(int left, int right) {
int i, j, temp, t;
i = left;
j = right;
if (left > right) {
return;
}
temp = a[left];
while (i != j) {
while (temp <= a[j] && i < j)
j--;
while (temp >= a[i] && i < j)
i++;
if (i < j) {
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
a[left] = a[i];
a[i] = temp;
f(left, i - 1);
f(i + 1, right);
}public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
int x = 0;
a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
f(0, n - 1);
for (int i = 1; i < a.length; i++) {
if (a[i - 1] == a[i]) {
x++;
a[i - 1] = Integer.MIN_VALUE;
}
}
System.out.println(n - x);
for (int i = 0; i < a.length; i++) {
if (a[i] != Integer.MIN_VALUE) {
if (i < a.length-1)
System.out.print(a[i] + " ");
else
System.out.println(a[i]);
}
}
}
in.close();
}
} -
02019-01-17 17:25:30@
这里用桶排相对来说更好
此处代码已优化桶排(仅限于需要去重的时候)#include <iostream> using namespace std; bool t[100001] = {false}; int main() { int i, j, tot = 0, n; cin >> j; for(i = 0; i < j; i++) { cin >> n; if(t[n] == false) { t[n] = true; tot++; } } cout << tot << endl; for(i = 0; i < 100001; i++) { if(t[i]) { cout << i << " "; } } return 0; }
-
02018-11-16 19:00:49@
#include <iostream>
#include <algorithm>
using namespace std;int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int x=0;
int y=0;
for(int i=0;i<n;i++){
if(x!=a[i]){
x=a[i];
y++;
}
}cout<<y<<endl;int z=0;
for(int i=0;i<n;i++){
if(z!=a[i]){
z=a[i];
cout<<z<<" ";
}
}return 0;
} -
02018-11-16 19:00:25@
#include <iostream>
#include <algorithm>
using namespace std;int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int x=0;
int y=0;
for(int i=0;i<n;i++){
if(x!=a[i]){
x=a[i];
y++;
}
}cout<<y<<endl;int z=0;
for(int i=0;i<n;i++){
if(z!=a[i]){
z=a[i];
cout<<z<<" ";
}
}return 0;
} -
02018-11-13 14:35:46@
why so water?
cpp
#include <bits/stdc++.h>
using namespace std;
int a[2000];
int main()
{
int n;
scanf("%d",&n);
for (int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
n=unique(a,a+n)-a;
printf("%d\n",n);
for (int i=0;i<n;i++)
printf("%d%c",a[i],i==n-1?'\n':' ');
return 0;
}
-
02018-11-04 20:54:37@
#include<iostream>
using namespace std;
int main()
{
int n;
int num[1001]={0},k;
int result=0;
int i;cin>>n;
for(i=1;i<=n;i++)
{
cin>>k;
if(num[k]==0) result++;
num[k]++;
}cout<<result<<endl;
for(i=1;i<=1000;i++)
if(num[i]) cout<<i<<" ";
cout<<endl;
return 0;
} -
02018-11-04 09:42:21@
c++代码
#include<bits/stdc++.h>
using namespace std;
int n,m=1,a[101];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(int i=2;i<=n;i++)
if(a[i]!=a[m]) a[++m]=a[i];
printf("%d\n",m);
for(int i=1;i<=m;i++) printf("%d ",a[i]);
return 0;
} -
02018-09-02 16:03:36@
python
#这题简单到不想解释 num=int(input()) students=list(map(int,input().split())) list=list(set(students)) list.sort() print(list.__len__()) for i in range(len(list)): print(list[i],end= ' ')
-
02018-07-24 16:43:45@
include <bits/stdc++.h>
using namespace std;
int n,a[105],b[105],ans;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(a[i]==a[i+1]) continue;//当有重复的时候看当前与下一个是否相同,相同就跳过。
b[ans++]=a[i];
}
cout<<ans<<endl;
for(int i=0;i<ans;i++){
cout<<b[i]<<((i+1==ans)?"\n":" ");//不是最后一个的时候输出空格,到最后一个的时候换行
}
return 0;
} -
02018-07-19 16:35:09@
思路:
类似数轴,每输入一个数,就在数轴上标出来,最后再查找有哪些数被标记了,并输出。
缺点:浪费空间#include<iostream>
using namespace std;
int a[1001];
int main()
{
int i,n,temp,counter=0;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>temp;
a[temp]=1;
}
for(i=1;i<=1000;i++)
{
if(a[i]==1)
counter++;
}
cout<<counter<<endl;
for(i=1;i<=1000;i++)
{
if(a[i]==1)
cout<<i<<" ";
}
return 0;
} -
02017-10-31 19:33:41@
#include<stdio.h>
int n,x,m;
bool f[1001];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&x);
if (!f[x])
{
m++;
f[x]=true;
}
}
printf("%d\n",m);
for (int i=1;i<1001;i++)
if (f[i])
printf("%d ",i);
return 0;
}