题解 | #首字母大写#
首字母大写
https://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a
#include <stdlib.h> #include <stdio.h> #include <string.h> #define len 2000 char res[len]; void initial_res(){ for(int i = 0;i<len;i++){ res[i] = '\0'; } } void bebigger(char*c){ *c = *c+('A'-'a'); } int isABC(char c){ if(c>='a'&&c<='z'||c>='A'&&c<='Z'){ return 1; } return 0; } void change(char str[],int n){ int flag = 0; if(isABC(str[0])==1){ bebigger(&str[0]); } for(int i = 0;i<n;i++){ if(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n'){ flag = 1; continue; } if(flag){ if(isABC(str[i])==1){ bebigger(&str[i]); } flag = 0; } } } int main(){ char str[len]; while(fgets(str,sizeof(str),stdin)){ int n = strlen(str)-1; //initial_res(); change(str,n); printf("%s\n",str); } }