fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int *max_divide(char s[][20] , int columnSize)
  4. {
  5. if(columnSize < 0)return NULL;
  6. int* retArr = (int*)malloc(sizeof(int)*columnSize);
  7. int max,min;
  8. for(int i=0;i < columnSize;i++)
  9. {
  10. max=s[i][0];
  11. min=s[i][0];
  12. for(int j = 0;s[i][j]!='\0';j++)
  13. {
  14.  
  15. if(s[i][j] > max)max = s[i][j];
  16. if(s[i][j] < min)min = s[i][j];
  17. }//找出這組的極大小值 找完再開始分割
  18. if(s[i][0]==max&&s[i][0]==min)//situation 1:陣列裡面都長一樣
  19. {
  20. int count = 0;
  21. while(s[i][count]!='\0')
  22. {
  23. count++;
  24. }
  25. retArr[i]=count;
  26. continue;
  27. }
  28. if(s[i][0]==max)//situation 2:陣列第一個剛好是最大值 那最多只能切割一組
  29. {
  30. retArr[i]=1;
  31. continue;
  32. }
  33.  
  34.  
  35. }
  36.  
  37. return retArr;
  38. }
  39. int main()
  40. {
  41.  
  42. char s [2][20]={"1111111","321"};
  43. int*arr =max_divide( s , 2);
  44. printf("%d\n",arr[0]);
  45. printf("%d",arr[1]);
  46. return 0;
  47. }
Success #stdin #stdout 0s 5412KB
stdin
Standard input is empty
stdout
7
1