Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <tuple>
  4. #include <string>
  5. #include <fstream>
  6. using namespace std;
  7. typedef unsigned long long int ull;
  8.  
  9. template <class A, class B>
  10. tuple<A,B> TupleAdd(tuple<A,B> Source, const tuple<A,B> & _b)
  11. {
  12. get<0>(Source) += get<0>(_b);
  13. get<1>(Source) += get<1>(_b);
  14. return Source;
  15. }
  16.  
  17. void get(ull u, ull a, ull q, ull p, ull d, map Get)
  18. {
  19. cout << '[' << Get[make_tuple(u, a, q, p, d)].get<0> << ']' << ' ' << '[' << Get[make_tuple(u, a, q, p, d)].get<1> << ']' << '\n';
  20. return;
  21. }
  22.  
  23. void clicked(ull u, map Clicked)
  24. {
  25. for(set<tuple>::iterator it = Clicked[u].begin(); it != Clicked[u].end(); ++ it){
  26. cout << *it << endl;////how to add [] [] into it???
  27. }
  28. return;
  29. }////set 是這樣叫他嗎?
  30.  
  31. void impressed(ull u1, ull u2, map Impressed)
  32. {
  33. for(set<tuple>::iterator it = Impressed[u1].begin(); it != Impressed[u1].end(); ++ it){
  34. if(Impressed[u2].find(*it)){
  35. cout << *it << endl; ////how to add [] [] into it???
  36. }
  37. }
  38. return;
  39. }
  40.  
  41. void profit(ull a, ull theta, map Profit)
  42. {
  43.  
  44. return;
  45. }
  46.  
  47. int main(int argc, char** argv)//why I definitely need this??-->because it put docname after the .exe
  48. {
  49. map< tuple<ull, ull, ull, ull, ull>, tuple<ull, ull> > Get;
  50. map< ull, set<tuple<ull, ull> > > Clicked;
  51. map< ull, set<tuple<string, string, ull, ull, ull> > > Impressed;
  52. map< tuple<ull, ull>, tuple<ull, ull> > Profit; // want to change to map<ull, set<map<ull, tuple<ull, ull>>>>, how to insert datas????
  53. ull user, ad, query, pos, depth, click, impre, keyword, title, description;
  54. string advertiser, URL;
  55. ifstream data(argv[1], ifstream::in);
  56. while(data.good()){
  57. //insert get
  58. data>>click>>impre>>URL>>ad>>advertiser>>depth>>pos>>query>>keyword>>title>>description>>user;
  59. Get[make_tuple(user, ad, query, pos, depth)] = TupleAdd(Get[make_tuple(user, ad, query, pos, depth)], make_tuple(click, impre));
  60. //insert clicked
  61. if(click > 0){
  62. //but same user same click too much!! Am I have to write a class?? --> try to use a set
  63. if(Clicked.find(user)){
  64. Clicked[user] -> second.insert(make_tuple(ad, query));
  65. }
  66. else if(!(Clicked.find(make_tuple(user, click)))){
  67. Clicked[make_tuple(user, click)].insert(make_tuple(ad, query));////Is that I don't need to tell by if??
  68. }
  69. }
  70. //insert impressed
  71. if(impre > 0){
  72. Impressed[user].insert(make_tuple(URL, advertiser, keyword, title, description));
  73. }////set.insert 這樣用對嗎?
  74. //insert profit
  75. if(Profit.find(make_tuple(user, ad))){
  76. Profit[make_tuple(user, ad)] = TupleAdd(Profit[make_tuple(user, ad)], make_tuple(click, impre));//how can I write this??
  77. }//Is that I only need to use TupleAdd instead of using if/else if ??
  78. else if(!(Profit.find(make_tuple(user, ad)))){
  79. Profit[make_tuple(user, ad)] = make_tuple(click, impre);
  80. }
  81. }
  82. data.close();
  83. //following the functions//
  84. //enter loop that not until Quit won't stop
  85. string command;
  86. cin >> command;
  87. while(strcmp(command, "quit") != 0){
  88. if(strcmp(command, get) == 0){
  89. ull u, a, q, p, d;
  90. //how to do like scanf("[%d]", &u)???
  91. cin >> [u] >> [a] >> [q] >> [p] >> [d];
  92. get(u, a, q, p, d, Get);
  93. }
  94. else if(strcmp(command, "clicked") == 0){
  95. ull u;
  96. cin >> [u];
  97. clicked(u, Clicked);
  98. }
  99. else if(strcmp(command, "impressed") == 0){
  100. ull u1, u2;
  101. cin >> [u1] >> [u2];
  102. impressed(u1, u2, Impressed);
  103. }
  104. else if(strcmp(command, "profit") == 0){
  105. ull a, theta;
  106. cin >> [a] >> [theta];
  107. profit(a, theta, Profit);
  108. }
  109. cin >> command;
  110. }
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement