xref: /linux-tools/drivers/mremap/napp.cpp (revision 74ce4ce33d5b8318cee71b38976a25818e666ff3)
1 #include <stdio.h>
2 #include <set>
3 
4 using namespace std;
5 
6 int total = 0;
7 #define MAXN 1024
8 int que[MAXN];
9 #define MOD 1000000007
10 
main()11 int main() {
12     long long v;
13     set<int> rs;
14     int h=0, i, ni, vv, rk;
15     while(1) {
16         printf("number>:");
17         scanf("%lld", &v);
18         if (v<=0) {
19             printf("total: %d\n", total);
20             if (total) {
21                 printf("Latest numbers are:");
22                 for (i=0; i<8&&i<total; i++) {
23                     ni=h-1-i; if (ni<0) ni+=MAXN;
24                     printf(" %d", que[ni]);
25                 } printf("\n");
26             }
27         } else {
28             que[h++]=v; if (h>=MAXN) h=0;
29             total++;
30             vv = (v*37)%MOD;
31             rs.insert(vv);
32             auto y = rs.lower_bound(vv);
33             rk = 0;
34             for (auto x = rs.begin(); x!=y; x++) rk++;
35             printf("your number has rank %d\n", rk+1);
36         }
37     }
38     return 0;
39 }
40