Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct nodo{
- char nombre[20];
- struct nodo *sig;
- }TNodo;
- typedef struct listacirc{
- TNodo *ini;
- TNodo *fin;
- int numElem;
- }TListaC;
- void L_init(TListaC *L){
- L->ini=NULL;
- L->fin=NULL;
- L->numElem=0;
- }
- void L_Insert(TListaC *L, char *nombre){
- TNodo *nodo=malloc(sizeof(TNodo));
- strcpy(nodo->nombre, nombre);
- if (L->numElem==0)
- L->ini=nodo;
- else
- L->fin->sig=nodo;
- nodo->sig=L->ini;
- L->fin=nodo;
- L->numElem++;
- }
- void L_delete(TListaC *L,TNodo *nodo){
- TNodo *crt=nodo->sig;
- if (crt==L->ini)
- L->ini=L->ini->sig;
- else if (crt==L->fin)
- L->fin=nodo;
- nodo->sig=crt->sig;
- free(crt);
- L->numElem--;
- }
- void RuletaRusa(TListaC *L,char *inicio,int k){
- //comenzamos en n
- TNodo *crt=L->ini;
- while (strcmp(crt->nombre,inicio)!=0){
- crt=crt->sig;
- }
- TNodo *ant;
- while (L->numElem>1){
- for (int i=0;i<k;i++){
- ant=crt;
- crt=crt->sig;
- }
- crt=crt->sig;
- L_delete(L,ant);
- }
- }
- void L_finalize(TListaC *L){
- TNodo *crt=L->ini;
- TNodo *ant;
- while (L->numElem>0){
- ant=crt;
- crt=crt->sig;
- L_delete(L,ant);
- }
- }
- int main(){
- int t,n,k;
- char *inicio=malloc(sizeof(20));
- char *s=malloc(sizeof(20));
- TListaC L;
- L_init(&L);
- scanf("%d",&t);
- while (t--){
- scanf("%d\n",&n);
- for (int i=0;i<n;i++){
- gets(s);
- L_Insert(&L,s);
- }
- //verificar esto
- gets(inicio);
- scanf("%d",&k);
- RuletaRusa(&L,inicio,k);
- printf("%s\n",L.ini->nombre);
- L_finalize(&L);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment