hdu java_HDU Java8 集锦
點擊打開鏈接?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();
}
總結
以上是生活随笔為你收集整理的hdu java_HDU Java8 集锦的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java面向对象小程序_java运用面向
- 下一篇: Win7如何共享xp的打印机(win11