[HDU] [2026] Capitalize the First Letter

Problem Description

Loading...

Problem Analysis

A pretty interesting problem
The key point here is that we get to know the gets input method besides scanf
The other is still using a “switch” x to mark whether it is the start of a new word

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<string.h>
int main() {
	char s[120];
	int x,i;
	while(gets(s)!=NULL) {
		for(i=0,x=0; i<strlen(s); i++) {
			if(s[i]==' ')
				x=0;
			if(x!=1&&s[i]!=' ') {
				s[i]=s[i]-('a'-'A');
				x=1;
			}
		}
		printf("%s\n",s);
	}
	return 0;
}

Loading...