fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct {
  6. char na[64];
  7. int stts[6];
  8. } Monster;
  9.  
  10. Monster creMonster(){
  11. int i,k;
  12. Monster tmp;
  13. k = rand()%8+4;
  14. int a = 'a' + rand()%26;
  15. for(i=0;i<k;i++)
  16. {
  17. tmp.na[i] = 'a' + rand()%26;
  18. }
  19. tmp.na[k] = '\0';
  20. for(i=0;i<6;i++)
  21. {
  22. tmp.stts[i] = rand()%255+1;
  23. }
  24. return tmp;
  25. }
  26.  
  27. void priMonster(Monster m){
  28. printf("%12s : ",m.na);
  29. for(int i=0;i<6;i++)
  30. {
  31. printf("%3d ",m.stts[i]);
  32. }
  33. printf("\n");
  34. }
  35.  
  36. int main(){
  37. srand((unsigned)time(NULL));
  38. int i, n;
  39. Monster *monsters;
  40. scanf("%d",&n);
  41. monsters=(Monster *)malloc(n *sizeof(Monster));
  42. if(monsters == NULL){
  43. printf("ERROR\n");
  44. return 0;
  45. }
  46. for(i=0;i<n;i++){
  47. monsters[i] = creMonster();
  48. printf("%03d ",i+1);
  49. priMonster(monsters[i]);
  50. }
  51. free(monsters);
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5284KB
stdin
6
stdout
001       pcphryu  :  31  43   5 169  60  23 
002        lidpls  : 193 254  87 217  46  33 
003        uquyfd  : 122 214 149 152   1  26 
004       pgjaoos  :  99 228 215 225 186 177 
005       tesjaqq  :  67  34 141  88 186  13 
006       twoezes  : 121  39 150  80   8  81