学一下c语言的string库isalpha,toupper,tolower就行了

#include <stdio.h>
#include <ctype.h>
#include <string.h>

void solve() {
    char str[1001]; 
    char ans[1001];
    scanf("%s", str);
    
    int p = -1;
    int ans_index = 0;

    for (int i = 0; str[i] != '\0'; i++) {
        if (isalpha(str[i])) {//判断特殊分割符号
            if (p == -1) {
                p = 0;
                ans[ans_index++] = toupper(str[i]);
            } else {
                ans[ans_index++] = tolower(str[i]);
            }
        } else {
            p = -1;
        }
    }
    ans[ans_index] = '\0';  
    printf("%s\n", ans);
}

int main() {
    int t = 1;
    scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

0 comments

No comments so far...

Information

ID
66
Time
ms
Memory
MiB
Difficulty
10
Tags
(None)
# Submissions
171
Accepted
2
Uploaded By