1 条题解
-
0
C :
#include<stdio.h> void main() { int a[1001]={0},i,n,t,r=0,s=0; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d",&t); if (!a[t]) s++; a[t]=1; } printf("%d\n",s); for (i=0;i<1001;i++) if (a[i]) { printf("%d",i); r++; if (r!=s) printf(" "); } }
C++ :
#include <iostream> #include<algorithm> using namespace std; int main() { int n; cin >> n; int a[100]; int b; int j; for (j = 0; n--;){ cin >> b; int i; for (i = 0; i < j; i++){ if (b == a[i]) break; } if (i == j){ a[j] = b; j++; } } sort(a, a + j); cout << j << endl; for (int i = 0; i < j;i++) if (i) cout << " " << a[i]; else cout << a[i]; }
Pascal :
var n,i,x,j:longint;a,b:array[1..1000]of longint; begin readln(n); for i:=1 to n do begin read(x); a[x]:=1 end; for i:=1 to 1000 do if a[i]=1 then begin inc(j);b[j]:=i;end; writeln(j); for i:=1 to j-1 do write(b[i],' ');write(b[j]) end.
Java :
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { TreeSet<Integer> set = new TreeSet<>(); Scanner s = new Scanner(System.in); int n = s.nextInt(); while(n>0){ int r = s.nextInt(); set.add(r); n--; } Integer num =null; System.out.println(set.size()); while((num = set.pollFirst())!=null){ System.out.print(num+" "); } } }
- 1
信息
- ID
- 246
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 1
- 上传者