Advertisement
juanjo12x

UVA_12554_Happy_Birthday

Jun 14th, 2014
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.     typedef struct reg{
  5.          char* letter;
  6.     }Treg;
  7.     typedef struct reg1{
  8.          char let[20];
  9.     }Treg1;
  10.     int main(int argc, char** argv) {
  11.         Treg song[16];int n;
  12.         song[0].letter="Happy";song[1].letter="birthday";song[2].letter="to";
  13.         song[3].letter="you";song[4].letter="Happy";song[5].letter="birthday";
  14.         song[6].letter="to";song[7].letter="you";song[8].letter="Happy";
  15.         song[9].letter="birthday";song[10].letter="to";song[11].letter="Rujia";
  16.         song[12].letter="Happy";song[13].letter="birthday";song[14].letter="to";
  17.         song[15].letter="you";
  18.         int cont=0;int cont1=0;int i,j;
  19.         Treg1 singers[100];
  20.        
  21.        while(scanf("%d",&n)==1)
  22.     {
  23.         char buffer[20]; char buf1[20];
  24.         for (i=0;i<20;i++) buffer[i]=0;
  25.         for (i=0;i<20;i++) buf1[i]=0;
  26.         for (i=0;i<n;i++){
  27.             scanf("%s",&buffer);
  28.             for (j=0;j<strlen(buffer);j++){
  29.                 singers[i].let[j]=buffer[j];
  30.             }
  31.             singers[i].let[j]='\0';
  32.            
  33.         }
  34.         if (n<16){
  35.             while (cont<16){
  36.                 i=0;
  37.                 while((i<n) && (cont!=16)){
  38.                     printf("%s: %s\n",singers[i].let,song[cont].letter);
  39.                     cont++;i++;
  40.                 }
  41.             }
  42.         }else{
  43.            
  44.             while(cont<n){
  45.                 i=0;
  46.                 while(i<16 && cont!=n){
  47.                    
  48.                     printf("%s: %s\n",singers[cont].let,song[i].letter);
  49.                     cont++;i++;
  50.                 }
  51.                        
  52.              
  53.             }
  54.             if(cont==n && i!=16){
  55.                 cont=0;
  56.                 for(j=i;j<16;j++){
  57.                     printf("%s: %s\n",singers[cont].let,song[j].letter);
  58.                     cont++;i++;
  59.                 }
  60.             }
  61.            
  62.         }
  63.       }
  64.         return (EXIT_SUCCESS);
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement