6 giờ trước

Code tham khảo nè

include <stdio.h>

include <string.h>

include <ctype.h>

int main() {

int n;
if (scanf("%d", &n) != 1) return 0;

while (getchar() != '\n');

for (int i = 0; i < n; i++) {
    char s[105];
    if (fgets(s, sizeof(s), stdin) == NULL) break;
    
    int len = strlen(s);
    while (len > 0 && (s[len - 1] == '\n' || s[len - 1] == '\r')) {
        s[len - 1] = '\0';
        len--;
    }
    
    int dc = 0; 
    int tu_moi = 1;
    
    for (int j = 0; s[j] != '\0'; j++) {
        if (s[j] != ' ') {
            if (dc > 0 && tu_moi) {
                putchar(' ');
            }
            if (tu_moi) {
                putchar(toupper(s[j]));
                tu_moi = 0;
            } else {
                putchar(tolower(s[j]));
            }
            dc++;
        } else {
            if (dc > 0) {
                tu_moi = 1;
            }
        }
    }
    putchar('\n');
}

return 0;

}

Trả lời 0 Phản hồi

Bạn cần đăng nhập để tham gia thảo luận

Đăng nhập ngay