[P2025问题概述]:查找最大元素
/**
* 查找最大元素
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 57081 Accepted Submission(s): 30661
Problem Description
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
Input
输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
Output
对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,
就在每一个最大字母后面都插入"(max)"。
Sample Input
abcdefgfedcba
xxxxx
Sample Output
abcdefg(max)fedcba
x(max)x(max)x(max)x(max)x(max)
Author
lcy
Source
C语言程序设计练习(四)
*/
代码演示:
package ac;
import java.util.Scanner;
public class P2025 {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in );
while (sc.hasNext()){
String str=sc.nextLine();
char max=str.charAt(0 );
for (char ch:str.toCharArray()){
if (ch>max){
max=ch;
}
}
str=str.replaceAll(max+"" , max+"(max)" );
System.out .println(str);
}
}
}
[P2026问题概述]:首字母变大写
/**
* 首字母变大写
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 60403 Accepted Submission(s): 33153
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
Author
lcy
Source
C语言程序设计练习(四)
*/
代码演示:
package ac;
import java.util.Scanner;
public class P2026 {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in );
while (sc.hasNext()){
String str=sc.nextLine();
char [] chs=str.toCharArray();
for (int i=0 ;i<chs.length;i++){
if (i==0 && chs[i]!=' ' || i>0 && chs[i-1 ]==' ' ){
chs[i]=(chs[i]+"" ).toUpperCase().toCharArray()[0 ];
}
System.out .print(chs[i]);
}
System.out .println();
}
}
}
[P2027问题概述]: 统计元音
/**
* 统计元音
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 71618 Accepted Submission(s): 28383
Problem Description
统计每个元音字母在字符串中出现的次数。
Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
Output
对于每个测试实例输出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多个测试实例之间由一个空行隔开。
请特别注意:最后一块输出后面没有空行:)
Sample Input
2
aeiou
my name is ignatius
Sample Output
a:1
e:1
i:1
o:1
u:1
a:2
e:1
i:3
o:0
u:1
Author
lcy
Source
C语言程序设计练习(四)
*/
代码演示:
package ac;
import java.util.Scanner;
public class P2027 {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in );
int n=sc.nextInt();
sc.nextLine();
while (n-->0 ){
String str=sc.nextLine();
int aCount=0 ;
int eCount=0 ;
int iCount=0 ;
int oCount=0 ;
int uCount=0 ;
char [] chs=str.toCharArray();
for (int i=0 ;i<chs.length;i++){
if (chs[i]=='a' ){
aCount++;
}else if (chs[i]=='e' ){
eCount++;
}else if (chs[i]=='i' ){
iCount++;
}else if (chs[i]=='o' ){
oCount++;
}else if (chs[i]=='u' ){
uCount++;
}
}
System.out .println("a:" +aCount);
System.out .println("e:" +eCount);
System.out .println("i:" +iCount);
System.out .println("o:" +oCount);
System.out .println("u:" +uCount);
if (n!=0 ){
System.out .println();
}
}
}
}
[P2028问题概述]: 最小公倍数
/**
* Lowest Common Multiple Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 60635 Accepted Submission(s): 25203
Problem Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
Author
lcy
Source
C语言程序设计练习(五)
*/
代码演示:
package ac;
import java.util.Arrays;
import java.util.Scanner;
public class P2028 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()){
int n=sc.nextInt();
int [] a=new int [n];
long sum =1 ;
for (int i=0 ;i<a.length;i++){
a[i]=sc.nextInt();
sum =sum *a[i];
}
Arrays.sort(a);
A:for (int t=a[a.length-1 ];t<=sum ;t++){
int count =0 ;
for (int i=0 ;i<a.length;i++){
if (t%a[i]==0 ){
count ++;
}
if (count ==a.length){
System.out.println(t);
break A;
}
}
}
}
}
}
[P2029问题概述]:回文串
/**
* Palindromes _easy version
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41353 Accepted Submission(s): 25156
Problem Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。
Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
Sample Input
4
level
abcde
noon
haha
Sample Output
yes
no
yes
no
Author
lcy
Source
C语言程序设计练习(五)
*/
代码演示:
package ac;
import java.util.Scanner;
public class P2029 {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in );
while (sc.hasNext()){
int n=sc.nextInt();
sc.nextLine();
while (n-->0 ){
String str=sc.nextLine();
char [] chs=str.toCharArray();
int count=0 ;
for (int i=0 ;i<chs.length;i++){
if (chs[i]==chs[chs.length-1 -i]){
count++;
}
}
if (count==chs.length){
System.out .println("yes" );
}else {
System.out .println("no" );
}
}
}
}
}