首页 > 试题广场 >

DAU 统计

[问答题]

DAU 统计

题目描述日活跃用户数 (DAU) 是衡量一个产品表现的重要指标。

需要编写程序,根据给定的某一天的 N 条访问记录,对当天的用户总数 M 进行统计。每个用户可能访问多次。为了方便,我们用数字 (uid) 唯一标识每个用户。

输入格式

每一行包含一个 uid,遇到 0 时认为输入结束。

输入共包含 N+1 行,可认为是无序的。

输出格式

一个数字:去重后 uid 的数量 M

输入样例

12933

111111

59220

69433

59220

111111

0

输出样例

4

数据范围

0 < uid < 2^63

时间 < 1s, 内存 < 32MB

对于 30% 的数据,0 < N < 100,000, 0 < M < 100,000

对于 100% 的数据,0 < N < 1,000,000, 0 < M < 800,000

推荐
#include <bits/stdc++.h>
using namespace std;//统计不重复的数字, 利用set就可以了
int main() {
    long long x;
    set<long long> st;
    while (cin >> x) {
        if (x == 0) break;
        st.insert(x);
    }
    cout << st.size() << endl;;
    return 0;
}

编辑于 2017-07-28 16:52:20 回复(0)
def DAU():
    lis=[]
    while True:
        v=input("输入uid:")
        if v=='0':
            break
        lis.append(v)
    return list(set(lis))

m=DAU()
print(len(m))

发表于 2019-07-29 11:20:17 回复(0)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // 直接使用set进行去重,然后输出set的size,即为不重复uid的数目
        HashSet<Long> set = new HashSet<>();
        Long num;
        while((num = Long.parseLong(br.readLine().trim())) != 0L)
            set.add(num);
        System.out.println(set.size());
    }
}

发表于 2021-01-28 20:48:42 回复(0)
import sys if __name__ == '__main__':
    a = int(sys.stdin.readline())
    b = [] while a != 0:
        b.append(a)
        a = int(sys.stdin.readline())
    b = list(set(b)) print(len(b))
发表于 2019-08-09 16:47:49 回复(0)
''' Time:2019-3-2 Input:  输入各个数字,以回车进行分割,输入0时输入结束 Output:  输出输入数字的不重复个数 ''' list=[] #定义一个列表 while True:
    a=input() #输入数字  if int(a)==0:#如果输入数字为0,输入结束  break  list.append(a) #将输入的数字保存到列表中 a=set(list) #将保存的数字运用set集合函数进行去重 for i in range(len(a)): #计算set集合中数字的个数  b=i+1 print(b)



发表于 2019-03-02 10:14:14 回复(0)
#include<iostream>
#include<vector>
#include<set>
using namespace std;
int main()
{
    set<int > DAU;
    int u;
    while(cin<<u)
    {
        if(u==0)
            break;
        if(DAU.count(u)==0)
            DAU.insert(u);
    }
    cout<<DAU.size();
}
发表于 2018-12-06 21:32:08 回复(0)
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n;
vector<string> data;
string s;
while ((cin >> s) != "0")
{
data.push_back(s);
}
sort(data.begin(), data.end());
int num = 1;
vector<string>::iterator it = data.begin();
for (it++; it != data.end(); it++)
{
if (*(it--) != *it)
num++;
}
system("pause");
return 0;
}

发表于 2017-08-23 19:20:18 回复(0)
package tests;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DAU {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        List<Integer> list=new ArrayList<Integer>();
        List<Integer> temp=new ArrayList<Integer>();
        int arg;
        while ((arg=scanner.nextInt())!=0) {
            temp.add(arg);        
        }
        
        for (int i = 0; i < temp.size(); i++) {
            System.out.println(temp.get(i));
            if (!list.contains(temp.get(i))) {
                list.add(temp.get(i));
            }
        }
        System.out.println(list.size());
    }

}
 
发表于 2017-08-01 16:58:32 回复(0)
import java.util.Scanner; import java.util.TreeSet;  public class Main {   public static void main(String[] args) {  // write your code here  Scanner in = new Scanner(System.in);  TreeSet treeSet = new TreeSet();  int a;  while (in.hasNext() ){  a = in.nextInt();  if (a!=0)  treeSet.add(a);  else  break;  }  System.out.println(treeSet.size());  } }



发表于 2017-07-31 23:02:12 回复(0)