372 条题解
-
-1qq913653500 LV 10 @ 2017-07-26 21:21:51
AC 第3862个
cpp
const maxlongint=100000000;
var
a:array[1..100000000]of longint;
i,j,n,k:longint;
begin
readln(n);
for i:=1 to n do
begin
read(j);
a[j]:=1;
end;
for i:=1 to maxlongint do
k:=k+a[i]; writeln(k);
for i:=1 to maxlongint do
if a[i]>0 then write(i,' ');
end.
-
-12017-07-24 22:30:30@
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int n,v,a[200],num;
set<int> ss;
int main()
{cin>>n;
num=1;
for(int i=1;i<=n;i++)
{
cin>>v;
if(ss.find(v)==ss.end())
{
a[num++]=v;
ss.insert(v);
}
}
sort(a+1,a+num);
cout<<num-1<<endl;
for(int i=1;i<num-1;i++)
cout<<a[i]<<" ";
cout<<a[num-1]<<endl;return 0;
} -
-12017-07-24 22:30:13@
#include<iostream> #include<algorithm> #include<set> using namespace std; int n,v,a[200],num; set<int> ss; int main() { cin>>n; num=1; for(int i=1;i<=n;i++) { cin>>v; if(ss.find(v)==ss.end()) { a[num++]=v; ss.insert(v); } } sort(a+1,a+num); cout<<num-1<<endl; for(int i=1;i<num-1;i++) cout<<a[i]<<" "; cout<<a[num-1]<<endl; return 0; }
-
-12017-07-24 22:29:22@
#include<iostream> #include<algorithm> #include<set> using namespace std; int n,v,a[200],num; set<int> ss; int main() { cin>>n; num=1; for(int i=1;i<=n;i++) { cin>>v; if(ss.find(v)==ss.end()) { a[num++]=v; ss.insert(v); } } sort(a+1,a+num); cout<<num-1<<endl; for(int i=1;i<num-1;i++) cout<<a[i]<<" "; cout<<a[num-1]<<endl; return 0; }
-
-12017-07-22 17:20:16@
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cassert>
#include <map>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;
int a[1001];
int main()
{
int N,i,x,s=0;
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%d",&x);
a[x]++;
}
for(i=0;i<=1000;i++)
{
if(a[i]>0)
{
s++;
}
}
printf("%d\n",s);
for(i=0;i<=1000;i++)
{
if(a[i]>0)
{
printf("%d ",i);
}
}
return 0;
} -
-12017-07-21 15:01:07@
就没人用 ostream_iterator 吗
```
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>int main([[maybe_unused]] int argc, [[maybe_unused]] const char *argv[])
{
int n;
std::cin >> n;
std::set<int> s;
for (int i = 0; i < n; ++i) {
int tmp;
std::cin >> tmp;
s.insert(tmp);
}
std::cout << s.size() << std::endl;
std::copy(s.begin(), s.end(),
std::ostream_iterator<int>(std::cout, " "));
}
``` -
-12017-07-08 20:18:26@
感觉桶排序方便,因为去重和排序相当于一起做掉了。
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; int main(){ bool numbers[1001]; memset(numbers, false, sizeof(numbers)); int n, c = 0; cin >> n; int num; for(int i = 0; i < n; i++){ cin >> num; if (!numbers[num]) numbers[num] = true, c++; } cout << c << endl; for (int i = 1; i < 1001; i++){ if (numbers[i]) cout << i << " "; } return 0; }
-
-12017-06-28 10:24:35@
var i,j,k,n,l,t:longint;
a:array[1..10000] of longint;
begin
read(n);
k:=n;
for i:=1 to k do
begin
read(l);
a[l]:=a[l]+1;
if a[l]>1 then
begin
a[l]:=1;
n:=n-1;
end;
end;
writeln(n);
for i:=1 to 1000 do
begin
if a[i]=1 then inc(t);
if t=n then
begin
writeln(i);
break;
end;
if a[i]=1 then write(i,' ');
end;
end. -
-12017-06-06 09:40:28@
主要需要用到sort函数进行排序,另外用两个数组进行去重处理,下面是只学了两天的我的题解,可能有点麻烦,见谅。
#include<iostream> #include <algorithm> int MAX,i=0,j=0,total=0; using namespace std; int main() { cin>>MAX; int a[MAX+2]={0},b[MAX+3]={0}; for (int n=2;n<MAX+2;n++) cin >> a[n]; // 排序开始 sort(a,a+MAX+2); //准备输出 for (i=2;i<MAX+2;) { if (a[i]-b[j]>=1 && a[i] != b[j-1]) { b[j]=a[i]; i++; j++; } if (a[i] == b[j-1]) { i++; } } for (j=0;j<MAX+3;j++) { if (b[j] !=0 ) total+=1; } cout<<total<<endl; for (j=0;j<MAX+3;j++) { if (b[j] !=0 ) cout<<b[j]<<' '; } return 0; }
-
-12017-05-22 19:28:50@
#include<iostream>
#include<algorithm>
#include<cstring>
const int MAXN = 100;
using namespace std;
int main(){
int n;
int s1[MAXN];
memset(s1,0,sizeof(s1));
cin >> n;
for(int i = 1;i <= n;i++){
cin >> s1[i];
}
sort(s1+1,s1+n+1);
int temp,x = 1;
for(int i = 1;i <= n-1;i++){
temp = s1[i+1];
if (s1[i] == temp){
s1[i] = 0;
continue;
}
x++;
}
cout << x << endl;
sort(s1+1,s1+n+1);
for(int i = n-x+1;i <= n;i++){
cout << s1[i];
if(i != n)
cout << ' ';
}
return 0;
} -
-12017-05-11 12:58:16@
比较暴力一点
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
const int maxn = 1005;
bool visited[maxn];
int a[maxn];
int main(){
int n;
cin >> n;
for(int i = 0;i< n;i++){
cin >> a[i];
}
for(int i = 0;i < n;i++){
visited[i] = true;
}
for(int i = 0;i < n;i++){
for(int j = i+1 ;j < n;j++){
if(a[i] > a[j] && i != j){
int temp = -1;
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for(int i = 0;i < n ;i++){
for(int j = i+1;j < n ;j++){
if(a[i] == a[j] && visited[i] && visited [j]){
visited[j] = false;
}
}
}
int counter = 0;
for(int i = 0;i < n;i++){
if(visited[i]){
counter++ ;
}
}
cout << counter << endl;
for(int i = 0;i < n;i++){
if(visited[i]){
printf("%d ",a[i]);
}
}return 0 ;
} -
-12017-04-06 17:46:56@
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[101];
bool b[101];
int n,sum=0;
fill(a,a+100,0);
scanf("%d",&n);
for(int i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=0;i<=n-1;i++)
{
if(a[i]!=a[i-1])sum++;
}
printf("%d\n",sum);
for(int i=0;i<=n-1;i++)
{
if(a[i]!=a[i-1])printf("%d%c",a[i],' ');
}
return 0;
} -
-12017-03-31 17:36:11@
#include <iostream>
using namespace std;
int n;
int number[1001]={0};
int main()
{
cin>>n;
int t,i;
int count=0;
for(int i=0;i<n;i++){
cin>>t;
if(number[t]!=1){
count++;
}
number[t]=1;
}
cout<<count<<endl;
for(i=0; i<1001;i++){
if(number[i]==1){
cout<<i<<" ";
}
}
cout<<endl;
return 0;
} -
-12017-02-28 06:00:12@
#include <stdio.h>
int main()
{
int N,i,temp,num=0,temp2;
scanf("%d",&N);
int n[1001];
for (i=0;i<=1000;i++) n[i]=0;
for (i=0;i<N;i++) { scanf("%d",&temp); n[temp]=1;}
for (i=1;i<=1000;i++) if(n[i]==1) num++;
int nn[num];int j=0;
for (i=1;i<=1000;i++) if(n[i]==1) { nn[j]=i;j++;}
for (i=0;i<num;i++)
{
temp=nn[i];temp2=i;
for (j=i;j<num;j++)
{
if (nn[j]<temp) {temp=nn[j];temp2=j;}
}
nn[temp2]=nn[i]; nn[i]=temp;
}
printf("%d\n",num);
for (i=0;i<num;i++) printf("%d ",nn[i]);
return 0;
} -
-12016-12-13 17:15:05@
秒杀!
c++
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[105],n,i,x;
cin>>n; for(i=0;i<n;i++) cin>>a[i];
sort(a,a+n); x=unique(a,a+n)-a;
cout<<x<<endl; for(int i=0;i<x;i++) cout<<a[i]<<" ";
return 0;
}
-
-12016-11-27 20:06:28@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #7: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #8: Accepted, time = 0 ms, mem = 508 KiB, score = 10 测试数据 #9: Accepted, time = 0 ms, mem = 508 KiB, score = 10 Accepted, time = 0 ms, mem = 508 KiB, score = 100 代码 #include <algorithm> #include <cstdio> using namespace std; int main() { //freopen("random.in","r",stdin); //freopen("random.out","w",stdout); bool hash[1001]; int n; fill(hash+1,hash+1000+1,false); scanf("%d",&n); for (int i = 1,x;i <= n;i++) { scanf("%d",&x); hash[x] = true; } printf("%d\n",count(hash+1,hash+1000+1,true)); for (int i = 1;i <= 1000;i++) if (hash[i]) printf("%d ",i); return 0; }
-
-12016-11-13 21:16:44@
#include<cstdio> #include<algorithm> using namespace std; int n,a[105]; int main(){ scanf("%d",&n); int ans=n; for(int i=0;i<n;i++){ scanf("%d",&a[i]); for(int j=i-1;j>=0;j--) if(a[i]==a[j]){ a[j]=-1; ans--; } } sort(a,a+n); printf("%d\n",ans); for(int i=0;i<n-1;i++) if(a[i]>0)printf("%d ",a[i]); printf("%d\n",a[n-1]); return 0; }
-
-12016-11-08 17:27:09@
#include<bits/stdc++.h>
using namespace std;
int n,ans=0;
int a[1010],num[110];
int main()
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for (int i=1;i<=n;++i){
int x;
scanf("%d",&x);
a[x]=1;
}
for (int i=1;i<=1000;++i) if (a[i]) num[++ans]=i;
printf("%d\n",ans);
for (int i=1;i<ans;++i) printf("%d ",num[i]);
printf("%d\n",num[ans]);
return 0;
}
简粗。 -
-12016-11-07 10:31:47@
用桶排序,轻松快捷(有些参考书上的桶排序好像不是这个意思)
测试数据 #0: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 808 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 812 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 808 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 804 KiB, score = 10
Accepted, time = 15 ms, mem = 812 KiB, score = 100
pascal
program P1316;
var
n:array[1..1000] of boolean;
k,i,sum,t:longint;
begin
readln(k);
fillchar(n,sizeof(n),false);
sum:=0;
for i:=1 to k do
begin
read(t);
if not n[t] then inc(sum);
n[t]:=true;
end;
writeln(sum);
for i:=1 to 1000 do if n[i] then write(i,' ');
end.
-
-12016-10-21 19:48:14@
var a,b:array[0..100] of integer;
n,i,k,l,m:integer;
procedure swap(var u,v:integer);
var t:integer;
begin
t:=u;
u:=v;
v:=t;
end;
procedure QS(l,r:integer);
var i,j,m:integer;
begin
m:=a[(l+r) div 2];
i:=l;
j:=r;
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then QS(l,j);
if i<r then QS(i,r);
end;
begin
readln(n);
l:=n;
for i:=1 to n do
read(a[i]);
QS(1,n);
m:=0;
for i:=1 to n do
if k<>a[i] then begin
k:=a[i];
dec(l);
inc(m);
b[m]:=a[i];
end;
writeln(n-l);
for i:=1 to m do write(b[i],' ');
end.