Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct lstInt{
  6. lstInt *r;
  7. lstInt *last;
  8. int val;
  9. lstInt() {
  10. r = nullptr;
  11. last = nullptr;
  12. val = 0;
  13. }
  14. };
  15. void pbInt(lstInt *root, int num) {
  16. if (!root->last) {
  17. root->r = new lstInt;
  18. root->last = root->r;
  19. root->last->val = num;
  20. return;
  21. }
  22. lstInt *v = root->last;
  23. v->r = new lstInt;
  24. v = v->r;
  25. v->val = num;
  26. root->last = v;
  27. }
  28. struct lstString{
  29. lstString *r;
  30. lstString *last;
  31. string val;
  32. lstString() {
  33. r = nullptr;
  34. last = nullptr;
  35. val = "";
  36. }
  37. };
  38. void pbString(lstString *root, string num) {
  39. if (!root->last) {
  40. root->r = new lstString;
  41. root->last = root->r;
  42. root->last->val = num;
  43. return;
  44. }
  45. lstString *v = root->last;
  46. v->r = new lstString;
  47. v = v->r;
  48. v->val = num;
  49. root->last = v;
  50. }
  51.  
  52. int main(){
  53. lstInt *rootInt = new lstInt;
  54. lstString *rootString = new lstString;
  55. int n;
  56. cin>>n;
  57. for (int i = 0 ; i < n ; ++ i) {
  58. string x;
  59. cin>>x;
  60. pbString(rootString, x);
  61. }
  62. for (int i = 0 ; i < n ; ++ i) {
  63. int x;
  64. cin>>x;
  65. pbInt(rootInt, x);
  66. }
  67. lstString *vS = rootString -> r;
  68. lstInt *vI = rootInt -> r;
  69. while (1) {
  70. cout<< vS->val << " got " << vI->val << "'s ticket"<<endl;
  71. if (vS->r == nullptr || vI->r == nullptr) break;
  72. else {
  73. vS = vS->r;
  74. vI = vI->r;
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement