Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct music{
  6.     string nome;
  7.     struct music *prox;
  8. };
  9.  
  10. struct playlist{
  11.     string nome;
  12.     struct playlist *next;
  13.  
  14.     struct music *prox;
  15. };
  16.  
  17. music *moveVmusic(music *head, string val){
  18.     music *cursor = head;
  19.     while(cursor && cursor->prox){
  20.         if(cursor->prox && cursor->prox->nome == val){
  21.             break;
  22.         }
  23.         cursor = cursor->prox;
  24.     }
  25.     return cursor;
  26. }
  27.  
  28. playlist *criarSent(playlist *cursor){
  29.     music *_new = new music;
  30.     _new->prox = cursor->prox;
  31.     _new->nome = "SentinelaMusical";
  32.     cursor->prox = _new;
  33.     return cursor;
  34. }
  35.  
  36.  
  37. playlist *insertPlay(playlist *cursor, string val){
  38.     playlist *_new = new playlist;
  39.     _new->nome = val;
  40.     _new->next = cursor->next;
  41.     cursor->next = _new;
  42.     return cursor;
  43. }
  44.  
  45. playlist *addPlay(playlist *cursor, string val){
  46.     while(cursor && cursor->next){
  47.         cursor = cursor->next;
  48.     }
  49.     cursor = insertPlay(cursor,val);
  50.     cursor->next->next = NULL;
  51.     cursor->next = criarSent(cursor->next);
  52.     return cursor;
  53. }
  54.  
  55. music *insertMusic(music *cursor, string val){
  56.     music *_new = new music;
  57.     _new->nome = val;
  58.     _new->prox = cursor->prox;
  59.     cursor->prox = _new;
  60.     return cursor;
  61. }
  62.  
  63. music *addMusic(music *cursor, string val){
  64.     while(cursor && cursor->prox){
  65.         cursor = cursor->prox;
  66.     }
  67.     cursor = insertMusic(cursor,val);
  68.     cursor->prox->prox = NULL;
  69.     return cursor;
  70. }
  71.  
  72. music *removMusic(music *cursor){
  73.     music *p = (music *)malloc(sizeof(music));
  74.     p = cursor->prox;
  75.     cursor->prox = p->prox;
  76.     free(p);
  77.     return cursor;
  78. }
  79.  
  80. int main(){
  81.  
  82.     int i, j = 0, k = 0, t =0;
  83.     int n;
  84.     int tamanho = 0;
  85.     int rep = -1000;
  86.  
  87.     string fun;
  88.     string play;
  89.     string song;
  90.     string song2;
  91.  
  92.     playlist *head = NULL;
  93.     playlist *cur = NULL;
  94.     playlist sent;
  95.  
  96.     music *aux = NULL;
  97.     music *curM = NULL;
  98.  
  99.     head = &sent;
  100.     cur = head;
  101.     cur->next = NULL;
  102.  
  103.     string f[100000];
  104.  
  105.     cin >> n;
  106.  
  107.     for(i=0;i<n;i++){
  108.         fflush(stdin);
  109.  
  110.         cin >> fun;
  111.  
  112.         if(fun[0] == 'A' && fun[1] == 'D' && fun[2] == 'D'){
  113.             k = 0;
  114.             j = 0;
  115.             cin >> play;
  116.             cur = head;
  117.             while(cur && cur->next){
  118.                 if(cur->next->nome == play){
  119.                     k = 1;
  120.                     break;
  121.                 }else{
  122.                     cur = cur->next;
  123.                 }
  124.             }
  125.             if(k != 1){
  126.                 cur = addPlay(cur,play);
  127.             }
  128.  
  129.             curM = cur->next->prox;
  130.             cin >> song;
  131.             curM = addMusic(curM,song);
  132.         }else if(fun[0] == 'D' && fun[1] == 'E' && fun[2] == 'L'){
  133.             k = 0;
  134.             j = 0;
  135.             cin >> play;
  136.             cur = head;
  137.             curM = cur->next->prox;
  138.             while(cur && cur->next){
  139.                 if(cur->next->nome == play){
  140.                     k = 1;
  141.                     break;
  142.                 }else{
  143.                     cur = cur->next;
  144.                 }
  145.             }
  146.  
  147.             cin >> song;
  148.  
  149.             if(k == 1){
  150.                 curM = cur->next->prox;
  151.                 curM = moveVmusic(curM,song);
  152.                 if(curM && curM->prox){
  153.                     curM = removMusic(curM);
  154.                 }
  155.             }
  156.         }else if(fun[0] == 'S' && fun[1] == 'W' && fun[2] == 'P'){
  157.             k = 0;
  158.             j = 0;
  159.             t = 0;
  160.             cin >> play;
  161.             cur = head;
  162.             curM = cur->next->prox;
  163.             while(cur && cur->next){
  164.                 if(cur->next->nome == play){
  165.                     k = 1;
  166.                     break;
  167.                 }else{
  168.                     cur = cur->next;
  169.                 }
  170.             }
  171.             cin >> song;
  172.             cin >> song2;
  173.             if(k == 1){
  174.                 curM = cur->next->prox;
  175.                 while(curM && curM->prox){
  176.                     if(curM->prox->nome == song){
  177.                         j = 1;
  178.                         break;
  179.                     }else{
  180.                         curM = curM->prox;
  181.                     }
  182.                 }
  183.                 aux = curM;
  184.                 curM = cur->next->prox;
  185.                 while(curM && curM->prox){
  186.                     if(curM->prox->nome == song2){
  187.                         t = 1;
  188.                         break;
  189.                     }else{
  190.                         curM = curM->prox;
  191.                     }
  192.                 }
  193.                 if(j == 1 && t == 1){
  194.                     curM->prox->nome == song;
  195.                     aux->prox->nome == song2;
  196.                 }
  197.             }
  198.         }else if(fun[0] == 'P' && fun[1] == 'L' && fun[2] == 'S'){
  199.             cin >> song;
  200.             if(tamanho == 0){
  201.                 rep = 0;
  202.             }
  203.             f[tamanho++] == song;
  204.         }else if(fun[0] == 'P' && fun[1] == 'L' && fun[2] == 'P'){
  205.             k = 0;
  206.             j = 0;
  207.             tamanho = 0;
  208.             cin >> play;
  209.             cur = head;
  210.             curM = cur->next->prox;
  211.             while(cur && cur->next){
  212.                 if(cur->next->nome == play){
  213.                     k = 1;
  214.                     break;
  215.                 }else{
  216.                     cur = cur->next;
  217.                 }
  218.             }
  219.             if(k == 1){
  220.                 curM = cur->next->prox;
  221.                 for(j=0;curM->prox;j++){
  222.                     f[tamanho++] = curM->prox->nome;
  223.                     curM = curM->prox;
  224.                 }
  225.             }
  226.             rep = 0;
  227.             if(tamanho == 0){
  228.                 rep = -1000;
  229.             }
  230.         }else if(fun[0] == 'N' && fun[1] == 'X' && fun[2] == 'T'){
  231.             if(rep != -1000){
  232.                 rep = rep + 1;
  233.             }
  234.         }else if(fun[0] == 'P' && fun[1] == 'R' && fun[2] == 'V'){
  235.             if(rep != -1000){
  236.                 rep = rep - 1;
  237.             }
  238.         }else if(fun[0] == 'C' && fun[1] == 'L' && fun[2] == 'R'){
  239.             tamanho = 0;
  240.             rep = -1000;
  241.         }else if(fun[0] == 'I' && fun[1] == 'N' && fun[2] == 'F'){
  242.             if(rep == -1000 || rep >= tamanho || rep < 0){
  243.                 cout << "UNKNOWN" << endl;
  244.             }else{
  245.                 cout << f[rep] << endl;
  246.             }
  247.         }
  248.  
  249.      //  printf("\n");
  250.       //  verplaylists(head);
  251.       //  printf("\n");
  252.       //  verfila(f,tamanho);
  253.      //   printf("\n");
  254.     }
  255.  
  256.  
  257.     return 0;
  258.  
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement