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
  • 相关阅读:
    Redis缓存穿透
    如何应对缓存穿透和缓存雪崩问题
    Redis缓存雪崩
    redis缓存机制
    C# LINQ学习笔记三:LINQ to OBJECT之操作字符串
    C# LINQ学习笔记二:LINQ标准查询操作概述
    C# LINQ学习笔记一:走进LINQ的世界
    C# Lambda表达式学习笔记
    C#委托与事件学习笔记
    C#泛型学习笔记
  • 原文地址:https://www.cnblogs.com/thx666/p/10864637.html
Copyright © 2011-2022 走看看