Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <tuple>
- #include <string>
- #include <fstream>
- using namespace std;
- typedef unsigned long long int ull;
- template <class A, class B>
- tuple<A,B> TupleAdd(tuple<A,B> Source, const tuple<A,B> & _b)
- {
- get<0>(Source) += get<0>(_b);
- get<1>(Source) += get<1>(_b);
- return Source;
- }
- void get(ull u, ull a, ull q, ull p, ull d, map Get)
- {
- cout << '[' << Get[make_tuple(u, a, q, p, d)].get<0> << ']' << ' ' << '[' << Get[make_tuple(u, a, q, p, d)].get<1> << ']' << '\n';
- return;
- }
- void clicked(ull u, map Clicked)
- {
- for(set<tuple>::iterator it = Clicked[u].begin(); it != Clicked[u].end(); ++ it){
- cout << *it << endl;////how to add [] [] into it???
- }
- return;
- }////set 是這樣叫他嗎?
- void impressed(ull u1, ull u2, map Impressed)
- {
- for(set<tuple>::iterator it = Impressed[u1].begin(); it != Impressed[u1].end(); ++ it){
- if(Impressed[u2].find(*it)){
- cout << *it << endl; ////how to add [] [] into it???
- }
- }
- return;
- }
- void profit(ull a, ull theta, map Profit)
- {
- return;
- }
- int main(int argc, char** argv)//why I definitely need this??-->because it put docname after the .exe
- {
- map< tuple<ull, ull, ull, ull, ull>, tuple<ull, ull> > Get;
- map< ull, set<tuple<ull, ull> > > Clicked;
- map< ull, set<tuple<string, string, ull, ull, ull> > > Impressed;
- map< tuple<ull, ull>, tuple<ull, ull> > Profit; // want to change to map<ull, set<map<ull, tuple<ull, ull>>>>, how to insert datas????
- ull user, ad, query, pos, depth, click, impre, keyword, title, description;
- string advertiser, URL;
- ifstream data(argv[1], ifstream::in);
- while(data.good()){
- //insert get
- data>>click>>impre>>URL>>ad>>advertiser>>depth>>pos>>query>>keyword>>title>>description>>user;
- Get[make_tuple(user, ad, query, pos, depth)] = TupleAdd(Get[make_tuple(user, ad, query, pos, depth)], make_tuple(click, impre));
- //insert clicked
- if(click > 0){
- //but same user same click too much!! Am I have to write a class?? --> try to use a set
- if(Clicked.find(user)){
- Clicked[user] -> second.insert(make_tuple(ad, query));
- }
- else if(!(Clicked.find(make_tuple(user, click)))){
- Clicked[make_tuple(user, click)].insert(make_tuple(ad, query));////Is that I don't need to tell by if??
- }
- }
- //insert impressed
- if(impre > 0){
- Impressed[user].insert(make_tuple(URL, advertiser, keyword, title, description));
- }////set.insert 這樣用對嗎?
- //insert profit
- if(Profit.find(make_tuple(user, ad))){
- Profit[make_tuple(user, ad)] = TupleAdd(Profit[make_tuple(user, ad)], make_tuple(click, impre));//how can I write this??
- }//Is that I only need to use TupleAdd instead of using if/else if ??
- else if(!(Profit.find(make_tuple(user, ad)))){
- Profit[make_tuple(user, ad)] = make_tuple(click, impre);
- }
- }
- data.close();
- //following the functions//
- //enter loop that not until Quit won't stop
- string command;
- cin >> command;
- while(strcmp(command, "quit") != 0){
- if(strcmp(command, get) == 0){
- ull u, a, q, p, d;
- //how to do like scanf("[%d]", &u)???
- cin >> [u] >> [a] >> [q] >> [p] >> [d];
- get(u, a, q, p, d, Get);
- }
- else if(strcmp(command, "clicked") == 0){
- ull u;
- cin >> [u];
- clicked(u, Clicked);
- }
- else if(strcmp(command, "impressed") == 0){
- ull u1, u2;
- cin >> [u1] >> [u2];
- impressed(u1, u2, Impressed);
- }
- else if(strcmp(command, "profit") == 0){
- ull a, theta;
- cin >> [a] >> [theta];
- profit(a, theta, Profit);
- }
- cin >> command;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement