fork download
  1. #include <string>
  2. #include <vector>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <iterator>
  7.  
  8. struct Transaction
  9. {
  10. bool m_isbuy;
  11. std::string trans_date;
  12. std::string trans_number;
  13. std::vector<std::string> trans_data;
  14. Transaction(bool isBuy = false) : m_isbuy(false) {}
  15. };
  16.  
  17. using namespace std;
  18.  
  19. void addToTransaction(Transaction& trans, const std::string& data, int nWhich)
  20. {
  21. switch (nWhich)
  22. {
  23. case 1:
  24. trans.trans_number = data;
  25. break;
  26. case 2:
  27. trans.trans_date = data;
  28. break;
  29. case 3:
  30. trans.m_isbuy = (data == "Buy");
  31. break;
  32. default:
  33. trans.trans_data.push_back(data);
  34. break;
  35. }
  36. }
  37.  
  38. void outputInformation(const Transaction& trans)
  39. {
  40. cout << "found " << (trans.m_isbuy ? "buy" : "sell") << "\n";
  41. cout << trans.trans_number << "\n";
  42. cout << trans.trans_date << "\n";
  43. cout << (trans.m_isbuy ? "Buy" : "Sell") << "\n";
  44. copy(trans.trans_data.begin(), trans.trans_data.end(), ostream_iterator<std::string>(cout, "\n"));
  45. }
  46.  
  47. int main()
  48. {
  49. const int numRecsPerTransaction = 7;
  50. std::string bufLine;
  51. int counter = 0;
  52. Transaction curTrans;
  53. while (getline(cin, bufLine))
  54. {
  55. addToTransaction(curTrans, bufLine, counter+1);
  56. ++counter;
  57. if (counter == 7)
  58. {
  59. outputInformation(curTrans);
  60. curTrans = Transaction();
  61. counter = 0;
  62. }
  63. }
  64. }
Success #stdin #stdout 0s 3436KB
stdin
198397652
2014-11-14 15:10 : 10
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198397685
2014-11-14 15:10 : 13
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198398295
2014-11-14 15:11 : 14
Buy
0.00517290
0.00100000
0.00100000
0.00000517
203440061
2014-11-21 16:13 : 13
Sell
0.00825550
0.00100000
0.00100000
0.00000826
stdout
found buy
198397652
2014-11-14 15:10 : 10
Buy
0.00517290
0.00100000
0.00100000
0.00000517
found buy
198397685
2014-11-14 15:10 : 13
Buy
0.00517290
0.00100000
0.00100000
0.00000517
found buy
198398295
2014-11-14 15:11 : 14
Buy
0.00517290
0.00100000
0.00100000
0.00000517
found sell
203440061
2014-11-21 16:13 : 13
Sell
0.00825550
0.00100000
0.00100000
0.00000826