zoukankan      html  css  js  c++  java
  • 寻找水王2

    一,题目说明

      随着论坛的发展,管理员发现水王没有了,但是统计结果表明,有三个发帖很多的ID。据统计他们的发帖数量超过了1/4,设计程序从发帖列表中快速找到他们。

    二,设计思路 

        由于发帖数超过四分之一,所以每次消除四个不同的id,用count来记录判断,最后剩下的就是那三个人。

    三,程序代码

    复制代码
    #include <iostream>
     
    using namespace std;
     
    int candidate[3];
    int count[3] = {0};
     
    int input[100];
    int num = 0;
     
    int main()
    {
        cout<<"please input"<<endl;
        int t;
        while(cin>>t)
        {
            if (t == -1)
                break;
            input[num++] = t;
        }
     
        bool flag = false;
     
        for (int i = 0;i < num;i++)
        {
            flag = false;
            for (int j = 0;j < 3;j++)
            {
                if (count[j] == 0)
                {
                    continue;
                }
                if (candidate[j] == input[i])
                {
                    count[j]++;
                    flag = true;
                }
            }
     
            if (flag == true)
            {
                continue;
            }
     
            for (int j = 0;j < 3;j++)
            {
                if (count[j] == 0)
                {
                    candidate[j] = input[i];
                    count[j]++;
                    flag = true;
                    break;
                }
            }
     
            if (flag == true)
            {
                continue;
            }
     
            for (int j = 0;j < 3;j++)
            {
                count[j]--;
            }
     
        }
     
        cout<<count[0]<<" "<<count[1]<<" "<<count[2]<<endl;
        cout<<candidate[0]<<" "<<candidate[1]<<" "<<candidate[2]<<endl;
    }
    复制代码

    程序截图:

  • 相关阅读:
    ajax请求超时
    tp5去重统计某字段的数量
    html本地存储 localStorge
    json、obj转换
    关于数组的合并arr.push() arr.push.apply()
    curl内容
    js 回车键登录
    tp5 前置操作
    STL容器
    c++文件的读写
  • 原文地址:https://www.cnblogs.com/a1264393659/p/6961938.html
Copyright © 2011-2022 走看看