Sunday, March 12, 2023

Codeforces Beta Round 55 (Div. 2) - 59 A. Word solution

 

Codeforces Beta Round 55 (Div. 2) - 59 A. Word solution

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int main() {
  6. #ifndef ONLINE_JUDGE
  7. freopen("input.txt", "r", stdin);
  8. freopen("output.txt", "w", stdout);
  9. #endif
  10. char s[101];
  11. scanf("%s", s);
  12. int upL=0, lowL=0;
  13. for(int i=0; i<strlen(s); i++) {
  14. //check how many uppercase letters
  15. if(isupper(s[i])!=0) upL++;
  16. //isupper() function of ctype.h checks whether the char ->
  17. //-> is a upper (or capital) letter, returns true ->
  18. //-> if it is upper letter. returns 0 if not
  19. } //check how many uppercase letters, for loop ends here
  20. for(int i=0; i<strlen(s); i++) {
  21. //check how many lower letters
  22. if(islower(s[i])!=0) lowL++;
  23. } //lower letter check loop ends here
  24. if(lowL<upL) { //checking if lower letter is less than upper letter
  25. for(int i=0; i<strlen(s); i++) {
  26. //if so then we need to convert all chars in string to uppercase
  27. s[i]=toupper(s[i]);
  28. //that is achieved by toupper() of ctype.h
  29. //basically we pass through all chars in a string
  30. //and convert them to upper letter
  31. }
  32. }
  33. else { //if lower letters are equal to or more than upper letters
  34. for(int i=0; i<strlen(s); i++) {
  35. s[i]=tolower(s[i]);
  36. //similar to toupper(). tolower() function of ctype.h helps us
  37. //to lowerletter all chars of a string
  38. }
  39. }
  40. printf("%s\n", s);
  41. //printf("up letter is %d\n", upL);
  42. //printf("low letter is %d\n", lowL);
  43. return 0;
  44. }

all necessary information is provided in the code. thanks




No comments:

Post a Comment