思路:
先定义一个变量f用来标记是否是单词的开始位置,如果是开始位置就输出大写字母,并把f标记成false,如果遇到空格,就把f标记成true。依次遍历字符串即可。
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
char a[100];
int i;
bool flag = true;
gets(a); //逐个过去字符串中的字符
for(i = 0; a[i] != '\0'; i++){
if(flag){
cout << (char)(a[i]-32);
flag = false;
}else{
cout << a[i];
}
if(a[i]==' '){
flag = true;
}
}
return 0;
}