zoukankan      html  css  js  c++  java
  • 每日一九度之 题目1041:Simple Sorting

    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:4883

    解决:1860

    题目描述:

    You are given an unsorted array of integer numbers. Your task is to sort this array and kill possible duplicated elements occurring in it.

    输入:

    For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array(1≤N≤1000). Next N lines contain N integer numbers(one number per each line) of the original array.

    输出:

    For each case ,outtput file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.

    样例输入:
    6
    8 8 7 3 7 7
    样例输出:
    3 7 8

    本来想用桶排做的,提交后发现runtime error,应该是数的范围太宽了。

    //Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cctype>
    #include <cstdlib>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <map>
    #include <string>
    #include <queue>
    #include <limits.h>
    #define INF 0x7fffffff
    using namespace std;
    const int maxn = 1005;
    typedef long long ll;
    int n, num;
    int a[maxn];
    
    int main(){
        while( ~scanf("%d",&n) ){
            memset(a,0,sizeof(a));
            while( n -- ){
                scanf("%d",&num);
                a[num] = 1;
            }
            int k = 0;
            for(int i=0; i<maxn; i++){
                if( a[i] ){
                    printf(k==0?"%d":" %d",i);
                    k ++;
                }
            }
            printf("
    ");
        }
        return 0;
    }

    正解,用STL中的set正好。简单,明了!!

    //Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cctype>
    #include <cstdlib>
    #include <stack>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <limits.h>
    #define INF 0x7fffffff
    using namespace std;
    const int maxn = 1005;
    typedef long long ll;
    int n, num;
    set<int> s;
    
    int main(){
        while( ~scanf("%d",&n) ){
            s.clear();
            while( n -- ){
                scanf("%d",&num);
                s.insert(num);
            }
            set<int>::iterator it;
            for(it=s.begin(); it!=s.end(); it++){
                printf(it==s.begin()?"%d":" %d",*it);
            }
            printf("
    ");
        }
        return 0;
    }
    低调做人,高调做事。
  • 相关阅读:
    通过Powershell开启RDP
    映射网络驱动器
    简易图书管理系统
    使用IDEA快速创建Spring Boot项目
    oracle11g安装步骤详细图文教程
    使用JDOM创建XML文档
    使用JDOM解析XML文档
    HTML+CSS之金立官网部分实现
    webstorm2019安装与使用详细教程
    第二章 JavaScript基础指令
  • 原文地址:https://www.cnblogs.com/Asimple/p/5889110.html
Copyright © 2011-2022 走看看