HDOJ 2026 首字母变大写
2017-12-20 20:27
239 查看
将输入的单词首字母变成大写并输出。
#include <cstdio>
#include <cctype>
const int MAX_SIZE = 100 + 2;
char words[MAX_SIZE];
//#define YANGYUAN
int main()
{
#ifdef YANGYUAN
freopen("in.txt", "r", stdin);
#endif // YANGYUAN
while (fgets(words, MAX_SIZE, stdin))
{
int i = 0;
// 如果第一个字符就是字母则大写输出并将下标后移一位
if (isalpha(words[i]))
printf("%c", toupper(words[i++]));
for (; i < MAX_SIZE && words[i] != '\n' && words[i] != '\0'; ++i)
{
// 如果前一个字符是非字母而当前字符是字母说明当前字母是单词的首字母
if (0 == isalpha(words[i - 1]) && isalpha(words[i]))
printf("%c", toupper(words[i]));
else
printf("%c", words[i]);
}
printf("\n");
}
return 0;
}
#include <cstdio>
#include <cctype>
const int MAX_SIZE = 100 + 2;
char words[MAX_SIZE];
//#define YANGYUAN
int main()
{
#ifdef YANGYUAN
freopen("in.txt", "r", stdin);
#endif // YANGYUAN
while (fgets(words, MAX_SIZE, stdin))
{
int i = 0;
// 如果第一个字符就是字母则大写输出并将下标后移一位
if (isalpha(words[i]))
printf("%c", toupper(words[i++]));
for (; i < MAX_SIZE && words[i] != '\n' && words[i] != '\0'; ++i)
{
// 如果前一个字符是非字母而当前字符是字母说明当前字母是单词的首字母
if (0 == isalpha(words[i - 1]) && isalpha(words[i]))
printf("%c", toupper(words[i]));
else
printf("%c", words[i]);
}
printf("\n");
}
return 0;
}
相关文章推荐
- hdoj 2026 首字母变大写 (字符串)
- 【hdoj2026】首字母大写
- hdoj2026 首字母变大写
- [热身题][hdoj_2026]首字母变大写
- HDOJ 2026 首字母变大写
- HDOJ2026 ( 首字母变大写 ) 【水题】
- HDOJ 2026 首字母变大写
- HDOJ2026 首字母变大写
- HDOJ 2026 首字母变大写
- hdoj 2026 首字母变大写
- hdoj2026 首字母变大写
- hdu 2026 首字母变大写
- HDU 2026 首字母变大写
- hdu 2026 首字母变大写(java)
- HDU - 2026 首字母变大写(water)
- HDU 2026 首字母变大写
- HDU-2026 首字母变大写
- [hdu 2026] 首字母变大写
- hdu 2026 首字母变大写
- HDU_2026 首写字母变大写