Third Blue Bridge Cup group C JAVA Nations Championship solution to a problem - [Blue Bridge Cup Software Engineering]

Fill in the blank 1. [Results] (out of 11 points)

Look at this formula:

☆ ☆ ☆. ☆ ☆ ☆. + = ☆ ☆ ☆.

If the five-pointed star each represent different numbers from 1 to 9.

How many possible methods correctly fill this formula there?

173 + 286 = 459
295 + 173 = 468
173 + 295 = 468
183 + 492 = 675

These are the correct method to fill in!

Note:
111 + 222 = 333 fill method is wrong!
Because each digit must be different!
In other words: all the numbers 1 to 9, and each must appear only once!

Note:
does not include the number "0"!

Note:
to meet the exchange rate equation addition count two different answers.
So the answer must be a even number!

Note:
The number of different computing requires only filling method
does not require the list to fill in all the law
but do not write the source code!

Do not write the answer here, please write "answer .txt" in!

Analysis Q & A:
Nations Championship saw this topic I am most happy, because this is a very popular knowledge, the whole arrangement, full array good variety of points, this problem simply do not order output in the dictionary, so all with exchange arrangement can easily get, of course, if the examination room plenty of time, then you can set nine cycle of violence, which I at the beginning of the blue bridge brush cup often Yongzhe Zhao, if sometimes forget how to write full array template can use this life-saving but be careful not to miss any weight.

Code:

public class Main03JC01 {
public static int ans=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[]={1,2,3,4,5,6,7,8,9};
dfs(0,a);
System.out.println(ans);
}
public static void dfs(int k,int res[]){
if(k==res.length){
int a=res[0]*100+res[1]*10+res[2];
int b=res[3]*100+res[4]*10+res[5];
int c=res[6]*100+res[7]*10+res[8];
if(a+b==c){
years ++ ;
return ;
}

}
for(int i=k;i<res.length;i++){
int temp=res[i];
res[i]=res[k];
res[k]=temp;
dfs(k+1,res);
temp=res[i];
res[i]=res[k];
res[k]=temp;
}
}
}

 

Answer: 336

 

[2] Code fill in the blank (12 minutes out)

/ * String "abcba" symmetrical with the letter "c" is about center; string "abba" is another mode symmetrical. In both cases we call this string is mirrored string. In particular, it contains only a letter string, the string can be seen as a mirror image of the first pattern.

A string may contain a number of image sub-string. Our goal is to find a maximum string substring mirror (mirror longest substring), if there are a plurality of maximum image substring, left center of symmetry of selected priority. For example: "abcdeefghhgfeiieje444k444lmn" maximum image substring is: "efghhgfe"

following static methods to achieve this function, please read and analyze the code carefully, fill in the blank space code, so that the logic of due process, the result is correct.
* /
// find the maximum (the maximum length) mirror-symmetrical sub-string
public static getMaxMirrorString String (String S)
{
String max_s = ""; // ask substring maximum symmetry

for (int i = 0; i <s.length (); i ++) // traverse the entire string, the idea is to force it enumeration, each letter over again from the beginning so that
{
// a first symmetrical pattern here should be traversed even length substring
int step = 1 ;
the try {
for (;;)
{
IF (! s.charAt (I-STEP) s.charAt = (I + STEP)) BREAK;
STEP ++;
}
} the catch (Exception E) {}

String s1 = s.substring(_____________________________); // 填空1

// 第二种对称模式
step = 0;
try{
for(;;)
{
if(_________________________________) break; // 填空2
step++;
}
}catch(Exception e){}

String s2 = s.substring(i-step+1,i+step+1);


if(s1.length() > max_s.length()) max_s = s1;
if(s2.length() > max_s.length()) max_s = s2;
}

return max_s;
}

[Note]
to fill only missing part, do not transcribe existing code.
The code does not fill more than one sentence (sentence does not contain semicolons)
filled code is no longer than 256 characters.
Write your answer "answer .txt" Do not write here!

Analysis and Solution:
(1)
there are test sites, I started to do a little Mongolian This question should be familiar with the test sites for the job, in fact, is to extract the string, not difficult
substring () method returns the string of sub-characters string.
beginIndex - start index (including), 0 indexed.
endIndex - End index (not included).
(2)
The second point is the same idea, the odd note on the line, vertically symmetric readily occur

参考答案:
i-step+1, i+step
s.charAt(i-step) != s.charAt(i+step+1)

 

3. Programming [Title] (out of 18 points)

A Children's Palace introduced a number of robot car. You can accept commands input in advance, according to the instruction action. The basic operation of the car is very simple, only three: left turn (referred to as L), right (referred to as R), to move forward several centimeters (Direct Digital mind).

For example, we can enter a command to the car as follows:

15L10R5LRR10R20

Then, before the car straight 15 cm, turn left, walk 10 centimeters, then turn right, ...

Not difficult to see, for this command string, the car returned to the departure.

Your task is: to write programs, entered by the user instruction, a straight line from the car before the car position and the position of the program output instruction execution after each instruction execution.

[Input] output format required

Users to enter an integer n (n <100), indicating that the following instructions will be n.

The next n input instructions. Each instruction only of L, R and numbers (the number is an integer between 0 and 100)

Each instruction length is no more than 256 characters.

N rows of the result output program.

Each result represents the trolley before and after performing the linear distance corresponding to the instruction position. It requires two rounded to one decimal.

For example: a user input:
. 5
L100R50R10
3LLL5RR4L12
LL
100R
5L5L5L5

The program output:
102.96
9.06
0.00
100.00
0.00


【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.


Analysis Q & A:
This question is a simulation title, and the provincial road race that Langton's Ant bit like, but Langton's Ant simpler than dealing with string, this question has difficulty dealing with a string, you can use substring methods, if unskilled substring method is to use way of multiplying one by one, fairly simple and requires patience, a good deal forward direction and two roads on it.

Code:

public class Main03JC03 {
public static String left="ULDR";
public static String right="URDL";
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
scan.nextLine();
for(int i=0;i<n;i++){
String a=scan.nextLine();
double res=getResult(a,0,0);
System.out.printf("%.2f",res);
System.out.println();
}

}
private static double getResult(String a, int x, int y) {
// TODO Auto-generated method stub
String turn="U";
for(int i=0;i<a.length();i++){
char order=a.charAt(i);
//    System.out.print(order);
//    int end=i;

if(order>='0'&&order<='9'){
int t=order-'0';
//    System.out.println("method1");
while(i<a.length()-1&&(a.charAt(i+1)>='0'&&a.charAt(i+1)<='9')){
t=t*10+(a.charAt(i+1)-'0');
i++;
}
//System.out.print(t+" ");
if(turn.equals("U")){
x=x-t;
t=0;
}else if(turn.equals("L")){
y=y-t;
t=0;
}else if(turn.equals("R")){
y=y+t;
t=0;
}else if(turn.equals("D")){
x=x+t;
t=0;
}
}else{
//    System.out.println("method2");
if(order=='L'){
if(turn.equals("U")){
turn="L";
}else if(turn.equals("L")){
turn="D";
}else if(turn.equals("D")){
turn="R";
}else if(turn.equals("R")){
turn="U";
}
}else{
if(turn.equals("U")){
turn="R";
}else if(turn.equals("R")){
turn="D";
}else if(turn.equals("D")){
turn="L";
}else if(turn.equals("L")){
turn="U";
}
}
//System.out.println(turn);
}
}
return Math.sqrt(x*x+y*y);
}
}

 

 

[4] the programming problem (out of 21 points)

Excel is the most popular office software. Each cell has a unique address representation. For example: The first line 12 is expressed as 4: "D12", row 5, as represented by 255 "IU5".

In fact, Excel provides two address representation, as well as a representation format called the RC address method. Column 4, line 12 is expressed as: "R12C4", row 5, as represented by 255 "R5C255".

Your task is: to write programs, transition from conventional RC address format to address format.

[Input] output format required

Users to enter an integer n (n <100), indicating that the following data has n input lines.

Then the input data line n is an RC cell address Excel format notation.

Program data is output n lines, each line is a conventional representation of the translated address.

For example: a user input:
2
R12C4
R5C255

The program should output:
D12
IU5


【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.

Analysis Q & A:
I represent now see EXECL analog programming problem I have to cry, did more than once almost did not do to before, said that she would like the provincial tournament there was a problem Leng Shimo want a night out, This question also good relatively simple, since the corresponding symbol relatively clear, as long as when debugging Minato good on it.

Code:

import java.util.Scanner;

public class Main03JC04 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
scan.nextLine();
for(int i=0;i<n;i++){
System.out.println(getResult(scan.nextLine()));
}
}

private static String getResult(String a) {
// TODO Auto-generated method stub
String resNumber="";
String resWord="";
for(int i=0;i<a.length();i++){
if(a.charAt(i)=='R'){
int t=a.charAt(i+1)-'0';
i++;
while(i<a.length()-1&&(a.charAt(i+1)>='0'&&a.charAt(i+1)<='9')){
t=t*10+a.charAt(i+1)-'0';
i++;
}
resNumber=t+"";
}else if(a.charAt(i)=='C'){
int t=a.charAt(i+1)-'0';
i++;
while(i<a.length()-1&&(a.charAt(i+1)>='0'&&a.charAt(i+1)<='9')){
t=t*10+a.charAt(i+1)-'0';
i++;
}
resWord="";
while(t>0){
char res=(char) ('A'-1+t%26);
t/=26;
resWord=res+resWord;
}
}
}
return resWord+resNumber+"";
}

}

 

 

[Title] 5. Programming (out of 34 points)

A secret unit confidential personnel, A, B, C, D, E need to work five days a week, 2 days.

The higher level each person weekly days and rest days arrangements must be fixed and can not change during the week.

In addition, because of work requirements, as well as the following requirements:

1. Everyone consecutive working days of no more than three days (Note: Sunday is continuously connected to next Monday).

2. In one week, at least three days everyone is to work.

3. On any given day in ABCD must ensure that there are at least two people to work.

4. BDE must rest day on Sunday.

5. AE Wednesday must be at work.

6. AC in one week must have at least four days to seeing (that is, at the same time to go to work).

Your task is: to write a program that lists all the possible scheduling of the week the situation ABCDE. 1 diary, a diary for the rest 0

ABCDE occupied by 1 per person rows, starting on Monday.

[Input] output format required

Enter the program does not require the output of all possible scenarios.

Each program is a 7x5 matrix. Only 1s and 0s.

Matrix column represents the day of the week, starting on Monday.

Rows of the matrix represent the A, B, C, D, E, timetable.

Among the plurality of matrices are separated by an empty line.

For example, the following matrix is ​​a qualified solution. Make all solutions programmed output (s solution before and after the order is not important).

0110111
1101110
0110111
1101110
1110110

【note】

Please debugging carefully! When your program can run only the correct result of a chance to score!

Please write all classes in the same file, debugging good, credited with [the candidates] folder corresponding to question number under "Answers .txt" can be.

Do not copy into the relevant project files.

Do not use a package statement.

JDK1.5 allowed syntax or call source program can only appear. You can not use version 1.6 or higher.

Analysis Q & A:
to be updated:

Code:
to be updated:

Guess you like

Origin www.cnblogs.com/yyyyfly1/p/11895709.html