Codeforces Beta Round 55 (Div. 2) - 59 A. Word solution
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- char s[101];
- scanf("%s", s);
- int upL=0, lowL=0;
- for(int i=0; i<strlen(s); i++) {
- //check how many uppercase letters
- if(isupper(s[i])!=0) upL++;
- //isupper() function of ctype.h checks whether the char ->
- //-> is a upper (or capital) letter, returns true ->
- //-> if it is upper letter. returns 0 if not
- } //check how many uppercase letters, for loop ends here
- for(int i=0; i<strlen(s); i++) {
- //check how many lower letters
- if(islower(s[i])!=0) lowL++;
- } //lower letter check loop ends here
- if(lowL<upL) { //checking if lower letter is less than upper letter
- for(int i=0; i<strlen(s); i++) {
- //if so then we need to convert all chars in string to uppercase
- s[i]=toupper(s[i]);
- //that is achieved by toupper() of ctype.h
- //basically we pass through all chars in a string
- //and convert them to upper letter
- }
- }
- else { //if lower letters are equal to or more than upper letters
- for(int i=0; i<strlen(s); i++) {
- s[i]=tolower(s[i]);
- //similar to toupper(). tolower() function of ctype.h helps us
- //to lowerletter all chars of a string
- }
- }
- printf("%s\n", s);
- //printf("up letter is %d\n", upL);
- //printf("low letter is %d\n", lowL);
- return 0;
- }
all necessary information is provided in the code. thanks
No comments:
Post a Comment