zoukankan      html  css  js  c++  java
  • 第几次出现

    问题描述
      涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。
    输入格式
      输入的第一行包含一个整数n,表示涛涛的记录条数。
      第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。
    输出格式
      输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。
    样例输入
    5
    1 2 1 1 3
    样例输出
    1 1 2 3 1
    评测用例规模与约定
      1≤n≤1,000,读者的编号为不超过n的正整数。
    #include<iostream>
    #include <stack>
    using namespace std;
    
    int countInter[1001];
    int Inter[10001];
    void main()
    {
        int n;
        stack<int> st;
        while (cin >> n)
        {
            memset(countInter, 0, 1001);
            memset(Inter, 0, 1001);
            for (int i = 0; i < n; ++i)
            {
                cin >> Inter[i];
                countInter[Inter[i]]++;
            }
    
            for (int j = n-1; j >= 0; --j)
            {
                st.push(countInter[Inter[j]]);
                countInter[Inter[j]]--;
            }
            while (!st.empty())
            {
                cout << st.top()<< ' ';
                st.pop();
            }
    
        }
    }

    优化一下:

    #include<iostream>
    using namespace std;
    
    int countInter[1001];
    int Inter[10001];
    void main()
    {
        int n;
        while (cin >> n)
        {
            memset(countInter, 0, 1001);
            memset(Inter, 0, 1001);
            for (int i = 0; i < n; ++i)
            {
                cin >> Inter[i];
                countInter[Inter[i]]++;
                cout << countInter[Inter[i]] << ' ';
            }
            cout << endl;
        }
    }

    此题属于Easy难度类型,看代码就可以明白,不再进行分析!

  • 相关阅读:
    人人学IoT 助学思维导图
    基于netty4.x开发时间服务器
    JAVA实现的截屏程序
    java获取硬盘ID以及MAC地址
    神经网络joone_engin模式识别示范,eclipse
    神经网络/人工智能 开源库
    双目测距
    OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波
    一个java 开源神经网络引擎 joone
    用Java开源项目JOONE实现人工智能编程
  • 原文地址:https://www.cnblogs.com/tgycoder/p/4989699.html
Copyright © 2011-2022 走看看