点击打开链接 HDU2026首字母变大写
Problem Description
输入一个英文句子,将每个单词的第一个字母改成大写字母。
Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
Output
请输出按照要求改写后的英文句子。
Sample Input
i like acm
i want to get an accepted
Sample Output
I Like Acm
I Want To Get An Accepted
String title(String s) {
String result = "";
char c = s.charAt(0);
if ('a' <= c && c <= 'z') {
result += (char) (c - 'a' + 'A');
} else {
result += c;
}
return result + s.substring(1);
}
void solve() {
while (in.hasNext()) {
String result =
Arrays.asList(in.nextLine().split(" "))
.stream()
.filter(word -> word != null && word.trim().length() != 0)
.map(word -> title(word))
.collect(Collectors.joining(" "));
out.println(result) ;
}
out.flush();
}
C语言合法标识符
Problem Description
输入一个字符串,判断其是否是C的合法标识符。
Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input
3
12ajf
fi8x_a
ff ai_2
Sample Output
no
yes
no
String judge(String word){
for(char c : word.toLowerCase().toCharArray()){
if(!(('a' <= c && c <= 'z') || (c == '_') || ('0' <= c && c <= '9'))){
return "no" ;
}
}
if('0' <= word.charAt(0) && word.charAt(0) <= '9'){
return "no" ;
}
return "yes" ;
}
void solve() {
List words = new ArrayList() ;
int t = in.nextInt() ;
while (t-- > 0) {
words.add(in.nextLine()) ;
}
words.stream()
.map(word -> judge(word))
.forEach(word -> out.println(word)) ;
out.flush();
}