zoukankan      html  css  js  c++  java
  • luogu P1059 明明的随机数

     

    传送门

     

    今天是2019.5.14 距离NOIP2019还有178天

    今天是我高二下学期以来第一次回到洛谷刷题

    NOIP2018考的很惨的我打算今年重新考一次 目标是省一

    从今天开始 我每天都要做一道题 拾起之前的知识

    六个月没写代码的我码力下降了许多

    言归正传

    今天做的是一道简单的排序水题

    题意大概就是去重+从小到大排序

    debug了一次是因为去重用的标记数组flag[i]未修改

    果然现在连写这种普及-的题都不能一次解决

    上代码

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<cctype>
    #include<cstdlib>
    #include<string>
    #include<iostream>
    #include<algorithm>
    #include<set>
    #include<map>
    #include<queue>
    #include<stack>
    #include<vector>
    #define enter puts("")
    #define space putchar(' ')
    using namespace std;
    typedef long long ll;
    int read()
    {
        int op = 1, ans = 0;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-') op = 0;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            ans *= 10;
            ans += ch - '0';
            ch = getchar();
        }
        return op ? ans : -ans;
    }
    void write(int x)
    {
        if(x < 0)
        {
            x = -x;
            putchar('-');
        }
        if(x >= 10) write(x / 10);
        putchar(x % 10 + '0');
    }
    int num, la[105], n;
    bool flag[1005];
    int main()
    {
        num = read();
        for(int i = 1;i <= num;i++)
        {
            int zs = 0;
            zs = read();
            if(flag[zs] == 0)
            {
                la[++n] = zs;
                flag[zs] = 1; 
            } 
        }
        write(n);
        enter;
        sort(la + 1, la + n + 1);
        for(int i = 1;i <= n;i++)
        {
            write(la[i]);
            space;
        }
        enter;
        return 0;
    }
    View Code
  • 相关阅读:
    P2082 区间覆盖(加强版)
    Java基础
    @import
    POST方式"Content-type"是"application/x-www-form-urlencoded 的请求遇到的问题
    VBox 安装 macOS 10.12
    对称加密和分组加密中的四种模式(ECB、CBC、CFB、OFB)
    window.location 属性
    post get 区别
    vue 生命周期
    记事本
  • 原文地址:https://www.cnblogs.com/thx666/p/10864637.html
Copyright © 2011-2022 走看看