Advertisement
Matqux

print team

Dec 7th, 2019
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include  <stdio.h>
  2. #include  <string.h>
  3. #include  <math.h>
  4.  
  5.  
  6. void write_spaces(int xnum, int rowlenght)
  7. {
  8.     int num_of_spaces = round((double)(rowlenght - xnum) / (double)(xnum+1));
  9.     for (int i = 0; i < xnum; i++)
  10.     {
  11.         for (int j = 0; j < num_of_spaces; j++)
  12.         {
  13.             printf(" ");
  14.         }
  15.         printf("X");
  16.     }
  17.     printf("\n");
  18. }
  19.  
  20. void write_players(char **str, int num, int rowlength)
  21. {
  22.     int lenght_of_names = 0;
  23.     for (int i = 0; i < num; i++)
  24.     {
  25.         lenght_of_names += strlen(str[i]);
  26.     }
  27.     int num_of_spaces = round((double)(rowlength - lenght_of_names) / (double)(num + 1));
  28.     for (int i = 0; i < num; i++)
  29.     {
  30.         for (int j = 0; j < num_of_spaces; j++)
  31.         {
  32.             printf(" ");
  33.         }
  34.         printf("%s", str[i]);
  35.     }
  36.     printf("\n");
  37.  
  38. }
  39.  
  40. void print_formation(char **p, int formation)
  41. {
  42.     int row_lenght = 150;
  43.     switch (formation)
  44.     {
  45.     case 244:
  46.     {
  47.         char *first_row[] = { p[0], p[1] };
  48.         char *second_row[] = { p[2], p[3], p[4], p[5] };
  49.         char *third_row[] = { p[6], p[7], p[8], p[9] };
  50.  
  51.         write_spaces(2, row_lenght);
  52.         write_players(first_row, 2, row_lenght);
  53.         printf("\n");
  54.  
  55.         write_spaces(4, row_lenght);
  56.         write_players(second_row, 4, row_lenght);
  57.         printf("\n");
  58.  
  59.         write_spaces(4, row_lenght);
  60.         write_players(third_row, 4, row_lenght);
  61.         printf("\n");
  62.     }
  63.         break;
  64.     default:
  65.         printf("Rosszul megadott formacio! Adjon meg letezo adatot.");
  66.         break;
  67.     }
  68. }
  69.  
  70. int main()
  71. {
  72.     char *str[10] = { "Korcsma Istvan",  "Programmer Pista",  "Vicces Valeria",  "Monoton Mark",  "Slager Tibor",  "Bunyos Pityu",  "Fasy Adam",  "Kis Grofo", "Skrillex", "The Midnight"};
  73.    
  74.     //formációk: 244, 334, 343, 433
  75.  
  76.     print_formation(str, 244);
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement