1, Question 6: classified counting (15 points)
(1) Title Description
Input a string, please output how many uppercase letters, lowercase letters and numbers the string contains.
[input format]
The input line contains a string.
[output format]
Output three lines, one integer per line, representing the number of uppercase letters, lowercase letters and numbers respectively.
[sample input]
1+a=Aab
[sample output]
1
3
1
[evaluation case scale and agreement]
For all evaluation cases, the string consists of visible characters with a length of no more than 100.
(2) Code implementation
import java.io.BufferedInputStream; import java.util.Scanner; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str=sc.nextLine(); sc.close(); int Big=0; int small=0; int digtal=0; for(int x=0;x<str.length();x++){//1+a=Aab if(str.charAt(x)>='a' && str.charAt(x)<='z'){ small++; } if(str.charAt(x)>='A' && str.charAt(x)<='Z'){ Big++; } if(str.charAt(x)>='0' && str.charAt(x)<='9'){ digtal++; } } System.out.println(Big); System.out.println(small); System.out.println(digtal); } }
2, Question 7: sum eight times (20 points)
(1) Title Description
[input format]
The first line of input contains an integer n.
[output format]
Output a line containing an integer representing the answer.
[sample input]
2
[sample output]
257
[sample input]
987654
[sample output]
43636805
[evaluation case scale and agreement]
For 20% of the evaluation cases, 1 ≤ n ≤ 20.
For 60% of the evaluation cases, 1 ≤ n ≤ 1000.
For all evaluation cases, 1 ≤ n ≤ 1000000.
(2) Code implementation
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger Bigmod = BigInteger.valueOf(123456789); BigInteger Bigsum = BigInteger.valueOf(0); int n=sc.nextInt(); for(int i=1;i<=n;i++){ BigInteger c = BigInteger.valueOf(i); Bigsum=Bigsum.add(c.multiply(c).multiply(c).multiply(c).multiply(c) .multiply(c).multiply(c).multiply(c)); } BigInteger sum = Bigsum.mod(Bigmod); System.out.println(sum); } }
3, Question 8: string encoding (20 points)
(1) Title Description
Xiao Ming invented A method to encode A string composed of all uppercase letters. For each capital letter, Xiao Ming converts it into its serial number in 26 English letters, that is, A → 1, B → 2,... Z → 26. Such A string can be converted into A sequence of numbers: for example, ABCXYZ → 123242526. Now, given A converted number sequence, Xiao Ming wants to restore the original string. Of course, such A restore may have multiple qualified strings. Xiao Ming hopes to find the word with the largest dictionary order
Character string.
[input format]
A sequence of numbers.
[output format]
A string containing only uppercase letters, representing the answer
[sample input]
123242526
[sample output]
LCXYZ
[evaluation case scale and agreement]
For 20% of the evaluation cases, the input length shall not exceed 20.
For all evaluation cases, the input length shall not exceed 200000.
(2) Code implementation
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] word = new char[27]; //Store 26 letters for(int i=0;i<26;i++) { word[i+1] = (char)('A'+i); } String str = sc.nextLine(); String[] s = str.split(""); int len = str.length(); int[] num = new int[len]; //Split each number for(int i=0;i<len;i++) { num[i] = Integer.parseInt(s[i]); } int index = 2; //Start indexing from the third number and mark to determine which number while(true) { //Go through the sequence from beginning to end if(index<len && num[index]!=0) { //Handle cases where there are no 0 int tmp = num[index-2]*10+num[index-1]; if(tmp<=26) { //Dictionary order, that is, the larger the letter, the more it should be in front, so first consider whether it can form two digits and be within the letter coding range System.out.print(word[tmp]); index+=2; } else { System.out.print(word[num[index-2]]); index+=1; } } else if(index<len && num[index]==0) { //Handle cases with 0 System.out.print(word[num[index-2]]); index+=1; } else if(index-1==len){ //It is not convenient when there is only one number left in the last sequence System.out.print(word[num[index-2]]); break; } else if(index==len) { //It's not convenient to have two digits left in the last series int tmp = num[index-2]*10+num[index-1]; if(tmp<=26) { System.out.print(word[tmp]); break; } else { System.out.print(word[num[index-2]]); index+=1; } } } } }