fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <sstream>
  5. #include <vector>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. struct User {
  11. string name; //Both first and last name go here
  12. int birthYear;
  13. string major;
  14. };
  15.  
  16. int main()
  17. {
  18. istream &input = cin;
  19.  
  20. if(!input)
  21. return -1;
  22.  
  23. string buffer;
  24. int count = -1;
  25. int index = 0;
  26. int size = 0;
  27. User* users;
  28.  
  29. while(getline(input, buffer, '\n'))
  30. {
  31. if(count == -1)
  32. {
  33. stringstream ss(buffer);
  34. ss >> size;
  35. users = new User[size];
  36. count = 0;
  37. }
  38. else
  39. {
  40. if(count == 0)
  41. {
  42. users[index].name = buffer;
  43. count++;
  44. }
  45. else if(count == 1)
  46. {
  47. stringstream ss(buffer);
  48. ss >> users[index].birthYear;
  49. count++;
  50. }
  51. else if(count == 2)
  52. {
  53. users[index].major = buffer;
  54. count = 0;
  55. index++;
  56. }
  57. }
  58. }
  59.  
  60. for(int i = 0; i < size; i++)
  61. {
  62. cout<<users[i].name << " " << users[i].birthYear << " " << users[i].major <<endl;
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0s 3436KB
stdin
3
Mohit
1983
Electronics
Somebody
1990
something
somebody_else
1992
something_else
stdout
Mohit 1983 Electronics
Somebody 1990 something
somebody_else 1992 something_else