fork download
  1. #include <bits/stdc++.h>
  2. #define MAX 10000001
  3. #define ll long long
  4. #define fastsync() \
  5.   ios_base::sync_with_stdio(false); \
  6.   cin.tie(NULL); \
  7.   cout.tie(NULL);
  8. const int mod = 1e9 + 7;
  9. using namespace std;
  10.  
  11. struct sp {
  12. string ms, ten, gia;
  13. };
  14.  
  15. struct node {
  16. sp data;
  17. node *next;
  18. };
  19.  
  20. void nhap(sp &x) {
  21. getline(cin, x.ms);
  22. getline(cin, x.ten);
  23. getline(cin, x.gia);
  24. }
  25.  
  26. node *makeNode(sp x) {
  27. node *newnode = new node;
  28. newnode->next = NULL;
  29. newnode->data = x;
  30. return newnode;
  31. }
  32.  
  33. void in(node *x) {
  34. cout << x->data.ms << ' ' << x->data.ten << ' ' << x->data.gia << endl;
  35. }
  36.  
  37. void duyet(node *head) {
  38. while (head != NULL) {
  39. in(head);
  40. head = head->next;
  41. }
  42. }
  43.  
  44. void themdau(node *&head, sp x) {
  45. node *newnode = makeNode(x);
  46. newnode->next = head;
  47. head = newnode;
  48. }
  49.  
  50. void xoadau(node *&head) {
  51. if (head == NULL)
  52. return;
  53. node *tmp = head;
  54. head = tmp->next;
  55. delete tmp;
  56. }
  57.  
  58. void tim(node *head, string s) {
  59. while (head != NULL) {
  60. if (head->data.ten == s) {
  61. in(head);
  62. return;
  63. }
  64. head = head->next;
  65. }
  66. cout << -1;
  67. }
  68.  
  69. int main() {
  70. fastsync();
  71. node *head = NULL;
  72. int c;
  73. while (1) {
  74. cin >> c;
  75. cin.ignore();
  76. if (c == 1) {
  77. int sl;
  78. cin >> sl;
  79. cin.ignore();
  80. cout << sl << endl;
  81. while (sl--) {
  82. sp moi;
  83. nhap(moi);
  84. themdau(head, moi);
  85. }
  86. }
  87. else if (c == 2) {
  88. string ten;
  89. getline(cin, ten);
  90. tim(head, ten);
  91. }
  92. else {
  93. xoadau(head);
  94. duyet(head);
  95. return 0;
  96. }
  97. }
  98. return 0;
  99. }
Success #stdin #stdout 0.01s 5500KB
stdin
1
3
1
but
10000
2
vo
50000
3
tay
30000
2
but
3
stdout
3
1 but 10000
2 vo 50000
1 but 10000