蓝桥杯程序设计大赛历年真题java实现Word下载.docx
- 文档编号:21762422
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:145
- 大小:86.16KB
蓝桥杯程序设计大赛历年真题java实现Word下载.docx
《蓝桥杯程序设计大赛历年真题java实现Word下载.docx》由会员分享,可在线阅读,更多相关《蓝桥杯程序设计大赛历年真题java实现Word下载.docx(145页珍藏版)》请在冰豆网上搜索。
(sourse);
tresult=newVector<
(result);
tresult.add(sourse.elementAt(i));
tsourse.remove(i);
newQuestion1().fullPermutation(tsourse,tresult);
}
publicstaticvoidmain(String[]args){
Scannerscanner=newScanner(System.in);
intn=scanner.nextInt();
Vector<
sourse=newVector<
();
result=newVector<
n;
sourse.add((char)('
A'
+i));
newQuestion1().fullPermutation(sourse,result);
System.out.println(Question1.count);
}
2.串的简单处理
串的处理
在实际的开发工作中,对字符串的处理是最常见的编程任务。
本题目即是要求程序对用户输入的串进行处理。
具体规则如下:
1.把每个单词的首字母变为大写。
2.把数字与字母之间用下划线字符(_)分开,使得更清晰
3.把单词中间有多个空格的调整为1个空格。
例如:
用户输入:
youandmewhatcpp2005program
则程序输出:
YouAndMeWhatCpp_2005_program
thisisa99cat
ThisIsA99_cat
我们假设:
用户输入的串中只有小写字母,空格和数字,不含其它的字母或符号。
每个单词间由1个或多个空格分隔。
假设用户输入的串长度不超过200个字符。
publicclassQuestion2{
Stringstring=scanner.nextLine();
vector=newVector<
string.length();
vector.add(string.charAt(i));
try{
intindex=0;
while(index<
vector.size()){
if(index==0&
&
vector.elementAt(index)>
='
a'
vector.elementAt(index)<
z'
){
vector.set(index,(char)(vector.elementAt(index)-('
-'
)));
}elseif(vector.elementAt(index-1)=='
'
vector.elementAt(index)=='
vector.remove(index);
index--;
}elseif(vector.elementAt(index-1)=='
(vector.elementAt(index)>
)){
}elseif((vector.elementAt(index)>
)&
(vector.elementAt(index-1)>
0'
vector.elementAt(index-1)<
9'
)){
vector.add(index,'
_'
index++;
}elseif((vector.elementAt(index-1)>
}
index++;
vector.size();
System.out.print(vector.elementAt(i));
System.out.println();
}catch(ArrayIndexOutOfBoundsExceptione){
//TODO:
handleexception
运行结果:
3.猜算式
看下面的算式:
□□x□□=□□x□□□
它表示:
两个两位数相乘等于一个两位数乘以一个三位数。
如果没有限定条件,这样的例子很多。
但目前的限定是:
这9个方块,表示1~9的9个数字,不包含0。
该算式中1至9的每个数字出现且只出现一次!
比如:
46x79=23x158
54x69=27x138
54x93=27x186
.....
请编程,输出所有可能的情况!
注意:
左边的两个乘数交换算同一方案,不要重复输出!
不同方案的输出顺序不重要
importjava.util.ArrayList;
importjava.util.List;
publicclassQuestion3{
publicstaticList<
Vector<
>
filteredNonRedundantResults;
privatestaticbooleanisfilter(Vector<
inta=(result.elementAt(0)-'
)*10+(result.elementAt
(1)-'
intb=(result.elementAt
(2)-'
)*10+(result.elementAt(3)-'
intc=(result.elementAt(4)-'
)*10+(result.elementAt(5)-'
intd=(result.elementAt(6)-'
)*100+(result.elementAt(7)-'
)*10+(result.elementAt(8)-'
if(a*b==c*d){
returntrue;
returnfalse;
publicstaticvoidprint(Vector<
vector){
System.out.printf("
%c%cx%c%c=%c%cx%c%c%c"
vector.elementAt(0),vector.elementAt
(1),vector.elementAt
(2),vector.elementAt(3),vector.elementAt(4),vector.elementAt(5),vector.elementAt(6),vector.elementAt(7),vector.elementAt(8));
privatestaticvoidfullPermutation(Vector<
if(sourse.size()==0&
isfilter(result)){
booleanexit=false;
filteredNonRedundantResults.size();
intra=(result.elementAt(0)-'
intrb=(result.elementAt
(2)-'
intfa=(filteredNonRedundantResults.get(i).elementAt(0)-'
)*10+(filteredNonRedundantResults.get(i).elementAt
(1)-'
intfb=(filteredNonRedundantResults.get(i).elementAt
(2)-'
)*10+(filteredNonRedundantResults.get(i).elementAt(3)-'
if(ra==fb&
rb==fa){
exit=true;
break;
if(exit==false){
filteredNonRedundantResults.add(newVector<
(result));
result.add(sourse.elementAt(i));
sourse.remove(i);
fullPermutation(sourse,result);
sourse.add(i,result.elementAt(result.size()-1));
result.remove(result.size()-1);
intn=9;
for(inti=1;
=n;
Question3.filteredNonRedundantResults=newArrayList<
Question3.fullPermutation(sourse,result);
Question3.filteredNonRedundantResults.size();
Question3.print(Question3.filteredNonRedundantResults.get(i));
运行结果:
58x67=29x134
58x69=23x174
58x73=29x146
58x96=32x174
63x74=18x259
64x79=32x158
73x96=12x584
76x98=14x532
4.Excel地址转换
Excel是最常用的办公软件。
每个单元格都有唯一的地址表示。
比如:
第12行第4列表示为:
“D12”,第5行第255列表示为“IU5”。
事实上,Excel提供了两种地址表示方法,还有一种表示法叫做RC格式地址。
“R12C4”,第5行第255列表示为“R5C255”。
你的任务是:
编写程序,实现从RC地址格式到常规地址格式的转换。
【输入、输出格式要求】
用户先输入一个整数n(n<
100),表示接下来有n行输入数据。
接着输入的n行数据是RC格式的Excel单元格地址表示法。
程序则输出n行数据,每行是转换后的常规地址表示法。
2
R12C4
R5C255
则程序应该输出:
D12
IU5
importjava.util.Stack;
publicclassQuestion4{
scanner.nextLine();
//必须加上的,不然会导致输入不准确!
while(n>
0){
Stringstring=scanner.nextLine();
Stringstrings[]=string.split("
C"
strings[0]=strings[0].substring(1,strings[0].length());
inthangshu=Integer.parseInt(strings[0]),lieshu=Integer.parseInt(strings[1]);
//获取行数和列数
/*
*对列数进行变换
*/
Stack<
stack=newStack<
while(lieshu>
0){
if(lieshu%26==0){
stack.push('
Z'
lieshu=lieshu/26-1;
}else{
stack.push((char)('
-1+lieshu%26));
lieshu=lieshu/26;
while(!
stack.empty()){
System.out.print(stack.pop());
System.out.println(hangshu);
n--;
输入一个整数n(n<
100)
5.手机尾号
/*
30年的改革开放,给中国带来了翻天覆地的变化。
2011全年中国手机产量约为11.72亿部。
手机已经成为百姓的基本日用品!
给手机选个好听又好记的号码可能是许多人的心愿。
但号源有限,只能辅以有偿选号的方法了。
这个程序的目的就是:
根据给定的手机尾号(4位),按照一定的规则来打分。
其规则如下:
1.如果出现连号,不管升序还是降序,都加5分。
5678,4321都满足加分标准。
2.前三个数字相同,或后三个数字相同,都加3分。
4888,6665,7777都满足加分的标准。
7777因为满足这条标准两次,所以这条规则给它加了6分。
3.符合AABB或者ABAB模式的加1分。
2255,3939,7777都符合这个模式,所以都被加分。
7777因为满足这条标准两次,所以这条标准给它加了2分。
4.含有:
6,8,9中任何一个数字,每出现一次加1分。
例如4326,6875,9918都符合加分标准。
其中,6875被加2分;
9918被加3分。
尾号最终得分就是每条标准的加分总和!
要求程序从标准输入接收数据,在标准输出上输出结果。
输入格式为:
第一行是一个整数n(<
100),表示下边有多少输入行,接下来是n行4位一组的数据,就是等待计算加分的手机尾号。
例如,输入:
14
3045
….
…..
6789
8866
则输出:
…
8
5
*/
publicclassQuestion5{
while((n--)>
Stringtelphone=scanner.nextLine();
intsum=0;
*情况一
if(telphone.charAt(0)-telphone.charAt
(1)==1){
charch=telphone.charAt(0);
intindex=0;
while(index<
4&
ch==telphone.charAt(index)){
ch--;
if(index>
=4){
sum+=5;
if(telphone.charAt(0)-telphone.charAt
(1)==-1){
ch++;
*情况二
if(telphone.charAt(0)==telphone.charAt
(1)&
telphone.charAt
(1)==telphone.charAt
(2)){
sum+=3;
if(telphone.charAt
(1)==telphone.charAt
(2)&
telphone.charAt
(2)==telphone.charAt(3)){
*情况三
if(telphone.charAt(0)==telphone.charAt
(1)&
sum+=1;
if(telphone.charAt(0)==telphone.charAt
(2)&
telphone.charAt
(1)==telphone.charAt(3)){
*情况四
4;
if(telphone.charAt(i)=='
6'
||telphone.charAt(i)=='
8'
sum+=1;
System.out.println(sum);
0211
……
6.括号问题
下面的代码用于判断一个串中的括号是否匹配所谓匹配是指不同类型的括号必须左右呼应,可以相互包含,但不能交叉
..(..[..]..)..是允许的
..(...[...)....]....是禁止的
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 蓝桥杯 程序设计 大赛 历年 java 实现