蓝桥杯 练习系统 基础练习答案Java.docx
《蓝桥杯 练习系统 基础练习答案Java.docx》由会员分享,可在线阅读,更多相关《蓝桥杯 练习系统 基础练习答案Java.docx(30页珍藏版)》请在冰豆网上搜索。
蓝桥杯练习系统基础练习答案Java
30
importjava.math.BigInteger;
importjava.util.*;
publicclassMain{
protectedstaticArrayListtable=newArrayList();
static{
table.add(BigInteger.valueOf
(1));
}
publicstaticsynchronizedBigIntegerfactorial(intx){
for(intsize=table.size();size<=x;size++){
BigIntegerlastfact=(BigInteger)table.get(size-1);
BigIntegernextfact=lastfact.multiply(BigInteger.valueOf(size));
table.add(nextfact);
}
return(BigInteger)table.get(x);
}
publicstaticvoidmain(String[]args){
Scanners=newScanner(System.in);
intn=s.nextInt();
System.out.print(factorial(n));
}
}
29
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassMain{
publicstaticvoidmain(String[]args)throwsNumberFormatException,IOException{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
Strings1=br.readLine();
Strings2=br.readLine();
inta[]=newint[100000];
intb[]=newint[100000];
intl1=s1.length();
intl2=s2.length();
for(inti=0;ia[l1-1-i]=Character.getNumericValue(s1.charAt(i));
}
for(inti=0;ib[l2-1-i]=Character.getNumericValue(s2.charAt(i));
}
intmax=l1>l2?
l1:
l2;
intc[]=newint[100000];
for(inti=0;ic[i]=a[i]+b[i];
}
for(inti=0;iif(c[i]>9){
c[i+1]+=c[i]/10;
c[i]=c[i]%10;
}
}
while(c[max-1]>9){
c[max]=c[max-1]/10;
c[max-1]=c[max-1]%10;
max++;
}
for(inti=max-1;i>=0;i--){
System.out.print(c[i]);
}
}
}
28
importjava.io.*;
importjava.math.BigInteger;
publicclassMain{
publicstaticvoidmain(String[]args)throwsIOException{
BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));
intn=Integer.parseInt(buf.readLine());
Stringstr=buf.readLine();
Strings[]=str.split("");
intsum=0;
inta[]=newint[n];
intnum=0;
for(inti=0;ia[i]=Integer.parseInt(s[i]);
java.util.Arrays.sort(a);
if(n>1){
sum=a[0]+a[1];
num=sum;
a[1]=num;
for(intj=2;jif(jjava.util.Arrays.sort(a);
num=a[j-1]+a[j];
a[j]=num;
java.util.Arrays.sort(a);
sum+=num;
}
}
}
else{
sum=a[0];
}
System.out.println(sum);
}
}
27
importjava.util.Scanner;
publicclassMain{
publicstaticintn=0;
publicstaticinta[]=newint[10];
publicstaticintisa[][]=newint[10][10];
publicstaticbooleanflag=false;
publicstaticintsum=0;
publicstaticbooleanjudge(intk){
for(intj=1;jif(Math.abs(j-k)==Math.abs(a[j]-a[k])||a[j]==a[k])
returnfalse;
}
returntrue;
}
publicstaticvoidplace(intt){
if(t>n&&!
flag){
flag=true;
place
(1);
flag=false;
}elseif(t>n&&flag){
sum++;
}else{
for(inti=1;i<=n;i++){
if(isa[t][i]==1){
inttemp=a[t];
a[t]=i;
if(judge(t)){
isa[t][i]=2;
place(t+1);
isa[t][i]=1;
}
a[t]=temp;
}
}
}
}
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
n=sc.nextInt();
for(inti=1;i<=n;i++){
for(intj=1;j<=n;j++){
isa[i][j]=sc.nextInt();
}
}
place
(1);
System.out.println(sum);
}
}
26
importjava.io.*;
publicclassMain{
publicstaticvoidmain(String[]args)throwsIOException{
BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));
Stringstr=buf.readLine();
Strings[]=str.split("");
StringBufferbf=newStringBuffer();
inti=Integer.parseInt(s[0]);
intn=Integer.parseInt(s[1]);
switch(i){
case0:
{
bf.append("zero");
break;
}
case1:
{
bf.append("one");
break;
}
case2:
{
bf.append("two");
break;
}
case3:
{
bf.append("three");
break;
}
case4:
{
bf.append("four");
break;
}
case5:
{
bf.append("five");
break;
}
case6:
{
bf.append("six");
break;
}
case7:
{
bf.append("seven");
break;
}
case8:
{
bf.append("eight");
break;
}
case9:
{
bf.append("nine");
break;
}
case10:
{
bf.append("ten");
break;
}
case11:
{
bf.append("eleven");
break;
}
case12:
{
bf.append("twelve");
break;
}
case13:
{
bf.append("thirteen");
break;
}
case14:
{
bf.append("fourteen");
break;
}
case15:
{
bf.append("fifteen");
break;
}
case16:
{
bf.append("sixteen");
break;
}
case17:
{
bf.append("seventeen");
break;
}
case18:
{
bf.append("eighteen");
break;
}
case19:
{
bf.append("nineteen");
break;
}
case20:
{
bf.append("twenty");
break;
}
case21:
{
bf.append("twentyone");
break;
}
case22:
{
bf.append("twentytwo");
break;
}
case23:
{
bf.append("twentythree");
break;
}
}
if(n==0){
bf.append("o'clock");
}
elseif(n/10<2){
switch(n){
case1:
{
bf.append("one");
break;
}
case2:
{
bf.append("two");
break;
}
case3:
{
bf.append("three");
break;
}
case4:
{
bf.append("Zero");
break;
}
case5:
{
bf.append("five");
break;
}
case6:
{
bf.append("six");
break;
}
case7:
{
bf.append("seven");
break;
}
case8:
{
bf.append("eight");
break;
}
case9:
{
bf.append("nine");
break;
}
case10:
{
bf.append("ten");
break;
}
case11:
{
bf.append("eleven");
break;
}
case12:
{
bf.append("twelve");
break;
}
case13:
{
bf.append("thirteen");
break;
}
case14:
{
bf.append("fourteen");
break;
}
case15:
{
bf.append("fifteen");
break;
}
case16:
{
bf.append("sixteen");
break;
}
case17:
{
bf.append("seventeen");
break;
}
case18:
{
bf.append("eighteen");
break;
}
case19:
{
bf.append("nineteen");
break;
}
}
}
else{
switch(n/10){
case2:
{
bf.append("twenty");
break;
}
case3:
{
bf.append("thirty");
break;
}
case4:
{
bf.append("forty");
break;
}
case5:
{
bf.append("fifty");
break;
}
}
switch(n%10){
case1:
{
bf.append("one");
break;
}
case2:
{
bf.append("two");
break;
}
case3:
{
bf.append("three");
break;
}
case4:
{
bf.append("four");
break;
}
case5:
{
bf.append("five");
break;
}
case6:
{
bf.append("six");
break;
}
case7:
{
bf.append("seven");
break;
}
case8:
{
bf.append("eight");
break;
}
case9:
{
bf.append("nine");
break;
}
}
}
System.out.println(bf.toString());
}
}
25
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.IOException;
publicclassMain{
/**
*@paramargs
*/
publicstaticvoidmain(String[]args)throwsIOException{
//TODOAuto-generatedmethodstub
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
int[]nm=newint[2];
String[]s=br.readLine().split("");
for(inti=0;i<2;i++){
nm[i]=Integer.parseInt(s[i]);
}
intm=nm[0],n=nm[1];
//System.out.println(n+""+m);
int[][]arr=newint[m][n];
for(inti=0;iStrings1=br.readLine();
String[]str=s1.split("");
for(intj=0;jarr[i][j]=Integer.parseInt(str[j]);
}
}
intnum=n*m,brr=0;
inti=0,j=0,x=0,y=0,z=0;
for(intii=0;iiif(jbrr=arr[i][j];
if(ii++;
}
x++;
}
elseif(jj++;
y++;
brr=arr[i][j];
}
elseif(j==y&&i>z){
i--;
brr=arr[i][j];
}
elseif(i==z&&j>z){
j--;
brr=arr[i][j];
if(i==z&&j==z+1){
z++;
i++;
m=m-1;
n=n-1;
x=z;
y=z;
}
}
System.out.print(brr+"");
}
}
}
24
importjava.io.*;
publicclassMain{
publicstaticvoidmain(String[]args)throwsException{
BufferedReaderbf=newBufferedReader(newInputStreamReader(System.in));
Stringstr[]=bf.readLine().split("");
intv1=Integer.parseInt(str[0]);
intv2=Integer.parseInt(str[1]);
intt=Integer.parseInt(str[2]);
ints=Integer.parseInt(str[3]);
intl=Integer.parseInt(str[4]);
intx=0,y=0,time=0;
for(inti=1;i<=l;i++){
if(x-yx+=v1;
y+=v2;
}
else{
for(intj=1;j<=s;j++){
i=i+1;
y+=v2;
if(y==l)
break;
}
i=i-1;
}
if(x==l||y==l){
time=i;
break;
}
}
if(y==l&&xSystem.out.println("T");
if(x==l&&ySystem.out.println("R");
if(y==l&&x==l)
System.out.println("D");
System.out.println(time);
}
}
23
importjava.io.*;
publicclassMain{
publicstaticvoidmain(String[]args)throwsException{
BufferedReaderbf=newBufferedReader(newInputStreamReader(System.in));
intn=Integer.parseInt(bf.readLine());
inta[][]=newint[n][n];
intb[]=newint[n*n];
inti=0,j=0;
for(i=0;iStrings[]=bf.readLine().split("");
for(j=0;ja[i][j]=Integer.parseInt(s[j]);
if(a[i][j]==0)
b[j]=b[j]+1;
}
}
for(i=0;iif(b[i]<=n/2)
System.out.print(i+1+"");
}
}
22
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassMain{
/**
*@paramargs
*@throwsIOException
*/
publicstaticvoidmain(String[]args)throwsIOException{
BufferedReaderbf=newBufferedReader(newInputStreamReader(System.in));
Strings=bf.readLine();
intn=Integer.parseInt(s);
Stringa="A";
f(n,a,1);
}
privatestaticvoidf(intn,Stringa,inti){
if(n==i){
System.out.println(a);
return;
}
else{
a=a+String.valueOf((char)(i+65))+a;
if(i==n){
System.out.println(a);
return;
}
}
//while(if(n,a,i+1);
}
}
21
importjava.util.Scanner;
publicclassMain{
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
intn=scanner