Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct music{
- string nome;
- struct music *prox;
- };
- struct playlist{
- string nome;
- struct playlist *next;
- struct music *prox;
- };
- music *moveVmusic(music *head, string val){
- music *cursor = head;
- while(cursor && cursor->prox){
- if(cursor->prox && cursor->prox->nome == val){
- break;
- }
- cursor = cursor->prox;
- }
- return cursor;
- }
- playlist *criarSent(playlist *cursor){
- music *_new = new music;
- _new->prox = cursor->prox;
- _new->nome = "SentinelaMusical";
- cursor->prox = _new;
- return cursor;
- }
- playlist *insertPlay(playlist *cursor, string val){
- playlist *_new = new playlist;
- _new->nome = val;
- _new->next = cursor->next;
- cursor->next = _new;
- return cursor;
- }
- playlist *addPlay(playlist *cursor, string val){
- while(cursor && cursor->next){
- cursor = cursor->next;
- }
- cursor = insertPlay(cursor,val);
- cursor->next->next = NULL;
- cursor->next = criarSent(cursor->next);
- return cursor;
- }
- music *insertMusic(music *cursor, string val){
- music *_new = new music;
- _new->nome = val;
- _new->prox = cursor->prox;
- cursor->prox = _new;
- return cursor;
- }
- music *addMusic(music *cursor, string val){
- while(cursor && cursor->prox){
- cursor = cursor->prox;
- }
- cursor = insertMusic(cursor,val);
- cursor->prox->prox = NULL;
- return cursor;
- }
- music *removMusic(music *cursor){
- music *p = (music *)malloc(sizeof(music));
- p = cursor->prox;
- cursor->prox = p->prox;
- free(p);
- return cursor;
- }
- int main(){
- int i, j = 0, k = 0, t =0;
- int n;
- int tamanho = 0;
- int rep = -1000;
- string fun;
- string play;
- string song;
- string song2;
- playlist *head = NULL;
- playlist *cur = NULL;
- playlist sent;
- music *aux = NULL;
- music *curM = NULL;
- head = &sent;
- cur = head;
- cur->next = NULL;
- string f[100000];
- cin >> n;
- for(i=0;i<n;i++){
- fflush(stdin);
- cin >> fun;
- if(fun[0] == 'A' && fun[1] == 'D' && fun[2] == 'D'){
- k = 0;
- j = 0;
- cin >> play;
- cur = head;
- while(cur && cur->next){
- if(cur->next->nome == play){
- k = 1;
- break;
- }else{
- cur = cur->next;
- }
- }
- if(k != 1){
- cur = addPlay(cur,play);
- }
- curM = cur->next->prox;
- cin >> song;
- curM = addMusic(curM,song);
- }else if(fun[0] == 'D' && fun[1] == 'E' && fun[2] == 'L'){
- k = 0;
- j = 0;
- cin >> play;
- cur = head;
- curM = cur->next->prox;
- while(cur && cur->next){
- if(cur->next->nome == play){
- k = 1;
- break;
- }else{
- cur = cur->next;
- }
- }
- cin >> song;
- if(k == 1){
- curM = cur->next->prox;
- curM = moveVmusic(curM,song);
- if(curM && curM->prox){
- curM = removMusic(curM);
- }
- }
- }else if(fun[0] == 'S' && fun[1] == 'W' && fun[2] == 'P'){
- k = 0;
- j = 0;
- t = 0;
- cin >> play;
- cur = head;
- curM = cur->next->prox;
- while(cur && cur->next){
- if(cur->next->nome == play){
- k = 1;
- break;
- }else{
- cur = cur->next;
- }
- }
- cin >> song;
- cin >> song2;
- if(k == 1){
- curM = cur->next->prox;
- while(curM && curM->prox){
- if(curM->prox->nome == song){
- j = 1;
- break;
- }else{
- curM = curM->prox;
- }
- }
- aux = curM;
- curM = cur->next->prox;
- while(curM && curM->prox){
- if(curM->prox->nome == song2){
- t = 1;
- break;
- }else{
- curM = curM->prox;
- }
- }
- if(j == 1 && t == 1){
- curM->prox->nome == song;
- aux->prox->nome == song2;
- }
- }
- }else if(fun[0] == 'P' && fun[1] == 'L' && fun[2] == 'S'){
- cin >> song;
- if(tamanho == 0){
- rep = 0;
- }
- f[tamanho++] == song;
- }else if(fun[0] == 'P' && fun[1] == 'L' && fun[2] == 'P'){
- k = 0;
- j = 0;
- tamanho = 0;
- cin >> play;
- cur = head;
- curM = cur->next->prox;
- while(cur && cur->next){
- if(cur->next->nome == play){
- k = 1;
- break;
- }else{
- cur = cur->next;
- }
- }
- if(k == 1){
- curM = cur->next->prox;
- for(j=0;curM->prox;j++){
- f[tamanho++] = curM->prox->nome;
- curM = curM->prox;
- }
- }
- rep = 0;
- if(tamanho == 0){
- rep = -1000;
- }
- }else if(fun[0] == 'N' && fun[1] == 'X' && fun[2] == 'T'){
- if(rep != -1000){
- rep = rep + 1;
- }
- }else if(fun[0] == 'P' && fun[1] == 'R' && fun[2] == 'V'){
- if(rep != -1000){
- rep = rep - 1;
- }
- }else if(fun[0] == 'C' && fun[1] == 'L' && fun[2] == 'R'){
- tamanho = 0;
- rep = -1000;
- }else if(fun[0] == 'I' && fun[1] == 'N' && fun[2] == 'F'){
- if(rep == -1000 || rep >= tamanho || rep < 0){
- cout << "UNKNOWN" << endl;
- }else{
- cout << f[rep] << endl;
- }
- }
- // printf("\n");
- // verplaylists(head);
- // printf("\n");
- // verfila(f,tamanho);
- // printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement