fork download
  1. #include <stdio.h>
  2.  
  3. #define LENGTH 14
  4.  
  5. int lengthOfWord(char * array, int idx, int size){
  6. int result = 0;
  7. while(idx < size && array[idx] != ' '){
  8. result ++;
  9. idx ++;
  10. }
  11. return result;
  12. }
  13.  
  14. int deleteWord(char * array, int i, int length, int size){
  15. int idx1 = i, idx2 = i+length;
  16. while(idx2 < size){
  17. array[idx1] = array[idx2];
  18. idx1++; idx2++;
  19. }
  20. return i;
  21. }
  22.  
  23. int main(void) {
  24. char array[LENGTH] = "aaa bbbbv rvvv";
  25. int numOfWords = 0;
  26. int totalLengthOfWords = 0;
  27. for(int i=0; i<LENGTH; i++){
  28. if(array[i] != ' '){ // prva bukva od zbor
  29. int l = lengthOfWord(array, i, LENGTH);
  30. totalLengthOfWords += l;
  31. numOfWords++;
  32. i+=(l-1);
  33. }
  34. }
  35. printf("%d/%d = ", totalLengthOfWords, numOfWords);
  36. printf("%d\n", totalLengthOfWords/numOfWords);
  37. int average = totalLengthOfWords/numOfWords;
  38. int numberOfDeletedWords = 0;
  39. int size = LENGTH;
  40. for(int i=0; i<LENGTH; i++){
  41. if(array[i] != ' '){ // prva bukva od zbor
  42. int l = lengthOfWord(array, i, LENGTH);
  43. if(l > average){
  44. deleteWord(array, i, l, size);
  45. size -= l;
  46. numberOfDeletedWords++;
  47. i--;
  48. }
  49. }
  50. }
  51. for(int i=0; i<size; i++){
  52. printf("%c", array[i]);
  53. }
  54. return 0;
  55. }
  56.  
  57.  
  58.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
12/3 = 4
aaa  rvvv