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. for(i=0;i<k;i++)tmp.na[i]='a'+rand()%26;
  15. tmp.na[k]='\0';
  16. for(i=0;i<6;i++)tmp.stts[i]=rand()%255+1;
  17. return tmp;
  18. }
  19.  
  20. void priMonster(Monster m){
  21. printf("%12s:",m.na);
  22. for(int i=0;i<6;i++)printf("%3d ",m.stts[i]);
  23. printf("\n");
  24. }
  25.  
  26. int main(){
  27. srand((unsigned)time(NULL));
  28. int i,n;
  29. Monster*monsters;
  30. scanf("%d",&n);
  31. monsters=(Monster*)malloc(sizeof(Monster)*n);
  32. if(monsters==NULL){
  33. printf("ERROR\n");
  34. return 0;
  35. }
  36. for(i=0;i<n;i++){
  37. monsters[i]=creMonster();
  38. printf("%03d ",i+1);
  39. priMonster(monsters[i]);
  40. }
  41. free(monsters);
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5320KB
stdin
5
stdout
001     dxbzexbr:198 118  81 183 138 216 
002        bqvlq: 62  16 254 205 167  58 
003   btyfyxixdf: 39 205 210 156 157   9 
004       xxfpst:179 151 250  49 100 162 
005         ooro: 39 225 136 172  30  32