Advertisement
Motocelium

PB 13.1

Jan 15th, 2024 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. //13.1//
  2.  
  3. //main.cpp
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stddef.h>
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     char s[101];
  12.    
  13.     scanf("%d ", &n);
  14.    
  15.     for(; n; n--)
  16.     {
  17.         scanf("%s", s);
  18.         char *p, *q;
  19.         p=strtok(s, ",");
  20.         q=p;
  21.         p=strtok(NULL, ",");
  22.        
  23.         int nr=0;
  24.        
  25.         while(p!=NULL && q!=NULL)
  26.         {
  27.             //printf("q=%s p=%s: ", q, p);
  28.             if(strcmp(p, "0")!=0 && strcmp(p, "0")!=0)
  29.             {
  30.                 printf("%s,", q);
  31.                 q=p;
  32.                 p=strtok(NULL, ",");
  33.             }
  34.            
  35.             else if(strcmp(p, "0")==0)
  36.             {
  37.                 while(strcmp(p, "0")==0 && p!=NULL)
  38.                 {
  39.                     nr++;
  40.                     p=strtok(NULL, ",");
  41.                     if(p==NULL)
  42.                         break;
  43.                 }
  44.                 printf("(%s,%d)", q, nr);
  45.                 q=p;
  46.                 p=strtok(NULL, ",");
  47.                 nr=0;
  48.                
  49.                 if(q) printf(",");
  50.             }
  51.         }
  52.        
  53.         if(q)
  54.             printf("%s", q);
  55.            
  56.         printf("\n");
  57.     }
  58. }
Tags: PCLP1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement