fork download
  1. #ifndef STRUCT08_H_
  2. #define STRUCT08_H_
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cassert>
  7. using namespace std;
  8.  
  9. struct complex_number {
  10. double real;
  11. double imaginary;
  12. };
  13.  
  14. istream& operator>>(istream& is, complex_number& cpx){
  15. is >> cpx.real >> cpx.imaginary;
  16. return is;
  17. }
  18.  
  19. ostream& operator<<(ostream& os, complex_number& cpx){
  20. os << cpx.real << " " << cpx.imaginary << endl;
  21. return os;
  22. }
  23.  
  24. class Judge{
  25. public:
  26. void check_init(){
  27. if(init == 0){
  28. cout << "Please call the init function first!" << endl;
  29. exit(0);
  30. }
  31. }
  32. void check_query(){
  33. if(query == 0){
  34. cout << "Please call Get_Query before answering!" << endl;
  35. exit(0);
  36. }
  37. query = 0;
  38. }
  39. void init_f(int &Q){
  40. cin >> Q;
  41. init = 1;
  42. }
  43. void query_f(int &N, complex_number*& cpx){
  44. cin >> N;
  45. if(first_time) cpx = (complex_number*)malloc(sizeof(complex_number)*1000);
  46. for(int i = 0; i < N; i++)
  47. cin >> cpx[i];
  48. query = 1;
  49. first_time = 0;
  50. }
  51. void answer_f(int N, complex_number* cpx){
  52. cout << N << endl;
  53. for(int i = 0; i < N; i++)
  54. cout << cpx[i];
  55. }
  56. private:
  57. int init = 0;
  58. int query = 0;
  59. int first_time = 1;
  60. };
  61.  
  62. Judge j;
  63.  
  64. void Init(int &Q){
  65. j.init_f(Q);
  66. }
  67.  
  68. void Get_Query(int &N,complex_number*& cpx){
  69. j.query_f(N, cpx);
  70. }
  71.  
  72. void Answer(int N,complex_number* cpx){
  73. j.answer_f(N, cpx);
  74. }
  75.  
  76. #endif // STRUCT08_H_
  77.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty