371 条题解

  • 0
    @ 2015-01-26 17:45:44

    hash,不想加注释。。

    Pascal Code

    var
    a:array[1..1000] of boolean;
    n,m,t,i,max,min:longint;
    begin
    read(n);
    max:=-maxlongint-1;
    min:=maxlongint;
    m:=0;
    fillchar(a,sizeof(a).0);
    for i:=1 to n do
    begin
    read(t);
    if not a[t] then inc(m);
    a[t]:=true;
    if t>max then max:=t;
    if t<min then min:=t;
    end;
    writeln(m);
    for i:=min to max do
    if a[i] then write(i,' ');
    end.

  • 0
    @ 2015-01-02 20:16:44

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
    int n,b[1001],tot=0,a[1001]={0};
    cin>>n;
    for(int i=1;i<=n;++i)
    {
    cin>>b[i];
    a[b[i]]=1;
    }
    for(int i=1;i<=1001;++i)
    {
    if(a[i]==1)
    tot=tot+1;
    }
    cout<<tot<<endl;
    for(int i=1;i<=1001;++i)
    {
    if(a[i]==1)
    cout<<i<<" ";
    }
    return 0;
    }

  • 0
    @ 2014-11-07 23:08:55

    测试数据 #0: Accepted, time = 0 ms, mem = 536 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 536 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 532 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 536 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 532 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 532 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 536 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    Accepted, time = 0 ms, mem = 536 KiB, score = 100

  • 0
    @ 2014-11-06 17:45:01

    感觉这题是专门用来练习set模板的
    #include<cstdio>
    #include<set>
    int main()
    {
    using namespace std;
    set<int>dict;
    int T,d;scanf("%d",&T);
    while(T--){
    scanf("%d",&d);
    dict.insert(d);}
    printf("%d\n",dict.size());
    for(set<int>::iterator it=dict.begin();it!=dict.end();it++)
    printf("%d ",*it);
    return 0;
    }

  • 0
    @ 2014-11-03 13:14:45

    program random;
    var i,j,m,n,k,t:integer;
    a,b:array[1..100]of integer;
    begin
    readln(n);
    for i:=1 to n do read(a[i]);
    for i:=1 to n-1 do
    for j:=i+1 to n do
    if (a[i]>a[j]) then
    begin
    m:=a[i]; a[i]:=a[j]; a[j]:=m;
    end;
    t:=a[1];m:=1;
    for i:=2 to n do
    if a[i]>t then
    begin
    t:=a[i]; m:=m+1;
    end;
    writeln(m);
    t:=a[1]; write(t);
    for i:=2 to n do

    if a[i]>t then
    begin
    t:=a[i]; write(' ',t);
    end;

    end.

  • 0
    @ 2014-10-06 20:41:12

    #include <iostream>
    #include <iterator>
    #include <algorithm>
    using namespace std;

    int arr[128];
    int t;
    int* end;

    int main(){
    cin>>t;
    end=arr+t;
    for (int* i=arr;i!=end;i++)
    cin>>*i;

    sort(arr,end);
    end=unique(arr,end);
    cout<<end-arr<<endl;
    copy(arr,end,ostream_iterator<int>(cout," "));
    cout<<endl;

    return 0;
    }

  • 0
    @ 2014-10-05 21:20:19

    #include <cstdio>

    unsigned int n;
    bool flag[1005];
    size_t number;

    unsigned int cnt(0);

    int main()
    {
    using namespace std;

    scanf("%u", &n);

    for (unsigned int i = 0;i != n;++i)
    {
    scanf("%u", &number);
    flag[number] = true;
    }

    for (size_t index = 0;index != 1005;++index)
    if (flag[index])
    ++cnt;

    printf("%u\n", cnt);

    for (size_t index = 0;index != 1005;++index)
    if (flag[index])
    printf("%u ", index);

    return 0;
    }

  • 0
    @ 2014-08-24 13:38:06

    #include <cstdio>
    #include <iostream>
    using namespace std;

    const int N=1001;

    int n,m;
    int a[N];

    int main()
    {int i,x;
    freopen("random.in","r",stdin);
    freopen("random.out","w",stdout);
    for (i=1;i<=N;i++)//标记所有的数都没有出现过
    a[i]=0;
    scanf("%d",&n);
    m=0;//记录出现过的数的个数
    for (i=1;i<=n;i++)
    {scanf("%d",&x);
    if (a[x]==0)//第一次出现
    {m++;
    a[x]=1;
    }
    }
    printf("%d\n",m);
    for (i=1;i<N;i++)
    if (a[i]==1)
    printf("%d ",i);
    return 0;
    }

  • 0
    @ 2014-08-16 18:56:05
    • 水中的水啊
  • 0
    @ 2014-08-16 18:55:35

    var
    a:array[1..1000] of longint;
    n,i,t,x:longint;
    begin
    readln(n);
    for i:=1 to n do
    begin
    read(x);
    if a[x]=0 then begin inc(t);a[x]:=1;end;
    end;
    writeln(t);
    for i:=1 to 1000 do if a[i]=1 then write(i,' ');
    end.

  • 0
    @ 2014-08-14 09:14:45

    program P1316;
    var
    a:array[1..100] of integer;
    n,m,i:integer;
    procedure qs(x,y:integer);
    var
    i,j,mid,temp:integer;
    begin
    i:=x;
    j:=y;
    mid:=a[(x+y) div 2];
    while i<j do
    begin
    while a[i]<mid do
    i:=i+1;
    while a[j]>mid do
    j:=j-1;
    if i<=j then
    begin
    temp:=a[i];
    a[i]:=a[j];
    a[j]:=temp;
    i:=i+1;
    j:=j-1;
    end;
    end;
    if x<j then qs(x,j);
    if i<y then qs(i,y);
    end;
    begin
    read(n);
    for i:=1 to n do
    read(a[i]);
    qs(1,n);
    m:=n;
    for i:=1 to n-1 do
    if a[i]=a[i+1] then m:=m-1;
    writeln(m);
    for i:=1 to n do
    if a[i]<>a[i+1] then write(a[i],' ');
    end.

  • 0
    @ 2014-08-07 08:09:39

    #include<iostream>
    #include<cstring>
    using namespace std;
    main()
    {
    int n,i,a[101],sum=0;
    bool b[1001];
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>a[i];
    memset(b,false,sizeof(b));
    for(i=1;i<=n;i++)
    if(!b[a[i]])
    {
    sum++;
    b[a[i]]=1;
    }
    cout<<sum<<endl;
    for(i=1;i<=1000;i++)
    if(b[i])
    cout<<i<<" ";
    }

  • 0
    @ 2014-08-01 17:51:07

    1次

    记录信息
    评测状态 Accepted
    题目 P1316 明明的随机数
    递交时间 2014-08-01 17:50:33
    代码语言 C++
    评测机 VijosEx
    消耗时间 15 ms
    消耗内存 272 KiB
    评测时间 2014-08-01 17:50:38
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 268 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    Accepted, time = 15 ms, mem = 272 KiB, score = 100

  • 0
    @ 2014-07-07 19:25:21

    #include <stdio.h>
    int main(){
    int arr[1001];
    int num,i,k;
    int count=0;
    scanf("%d",&num);
    for(i=1;i<=1000;i++)
    arr[i]=0;
    for(i=0;i<num;i++){
    scanf("%d",&k);
    if(arr[k]!=1){
    count++;
    arr[k]=1;
    }
    }
    printf("%d\n",count);
    for(i=1;i<=1000;i++)
    if(arr[i]==1)
    printf("%d ",i);
    printf("\n");
    return 0;
    }

    桶排够快

  • 0
    @ 2014-05-19 23:15:05

    简单的,问题边输入边存储值。
    for(int i=1;i<=n;i++){
    scanf("%d",&t);
    if(!a[t]){
    a[t]=1;count++;
    }
    }

  • 0
    @ 2014-04-27 02:16:20

    #include <cstdio>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main(void){
    vector<int>v;
    int n;
    scanf("%d\n",&n);
    for(int i=0; i<n; i++){
    int tmp;
    scanf("%d ",&tmp);
    v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    printf("%lu\n",v.size());
    for (int i=0; i<v.size(); i++) {
    printf("%d ",v[i]);
    }
    printf("\n");
    }

  • 0
    @ 2014-04-09 17:15:33

    program p1316;
    var
    a:array[1..100000]of longint;
    c,n,i,j,b:longint;
    begin
    read(n);c:=n;
    for i:=1 to n do read(a[i]);
    for i:=1 to n-1 do
    for j:=i+1 downto 1 do
    if a[j]<a[j-1] then begin
    b:=a[j];a[j]:=a[j-1];a[j-1]:=b;end;
    for i:=2 to n do if a[i]=a[i-1] then begin dec(c);a[i-1]:=0;end;
    writeln(c);
    for i:=1 to n do if a[i]>0 then write(a[i],' ');
    end.
    最简单的冒泡都能过

  • 0
    @ 2014-02-28 17:31:39

    用哈希映射法,16行完事!

    #include<iostream>
    using namespace std;
    int a[1001],n,k,i,js;
    int main()
    {
    cin>>n;
    for(i=1;i<=n;i++)cin>>k,a[k]=k;
    for(i=0;i<=1000;i++)
    if(a[i]!=0)js++;
    cout<<js<<endl;
    for(i=0;i<=1000;i++)
    if(a[i]!=0)cout<<a[i]<<" ";
    cout<<endl;
    system("pause");
    return 0;
    }

    编译成功

    测试数据 #0: Accepted, time = 7 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 276 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    Accepted, time = 52 ms, mem = 276 KiB, score = 100

  • 0
    @ 2014-02-24 16:10:49

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[101],b[101],m,n;
    int cmp(const int &a, const int &b ){
    if( a < b )
    return 1;
    else
    return 0;
    }
    int main()
    {

    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];

    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)
    if(a[i]!=a[i-1]) {m++;b[m]=a[i];}
    cout<<m;
    cout<<endl;
    for(int i=1;i<=m;i++)
    cout<<b[i]<<" ";
    return 0;

    }

  • 0
    @ 2014-02-13 09:59:55

    var a,b:array[1..2000] of longint;
    n,i,num,k:longint;
    begin
    readln(n);
    for i:=1 to n do
    begin
    read(k);
    a[k]:=a[k]+1;
    end;
    for i:=1 to 2000 do if a[i]<>0 then num:=num+1;
    writeln(num);
    for i:=1 to 2000 do if a[i]>0 then
    write(i,' ');
    end.

信息

ID
1316
难度
3
分类
其他 | 排序 点击显示
标签
递交数
9946
已通过
4861
通过率
49%
被复制
29
上传者