题目来源: http://ac.jobdu.com/oldexamset.php
题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =
three four + five six =
zero seven + eight nine =
zero + zero =
样例输出:
3
90
96
public class a_b_2005 {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
String s=null;
int a=0;
int b=0;
Mapmap=new HashMap();
map.put("zero",0);
map.put("one",1);
map.put("two", 2);
map.put("three", 3);
map.put("four", 4);
map.put("five", 5);
map.put("six", 6);
map.put("seven", 7);
map.put("eight", 8);
map.put("nine",9);
while(true){
s=cin.next();
if (s.equals("+")) {
b=a;//记住前一个数
a=0;
continue;
}
if (s.equals("=")){
if ((a==0)&&(b==0)) break;
System.out.println(a+b);
a=0;
b=0;
continue;
}
a=a*10+map.get(s);
}
}
}
测试输入包含若干测试用例,每个测试用例占2行,第1行给出正整数K( K< 10000 ),第2行给出K个整数,中间用空格分隔。当K为0时,输入结束,该用例不被处理。
对每个测试用例,在1行里输出最大和、最大连续子序列的第一个和最后一个元素,中间用空格分隔。如果最大连续子序列不唯一,则输出序号i和j最小的那个(如输入样例的第2、3组)。若所有K个元素都是负数,则定义其最大和为0,输出整个序列的首尾元素。
6 -2 11 -4 13 -5 -2 10 -10 1 2 3 4 -5 -23 3 7 -21 6 5 -8 3 2 5 0 1 10 3 -1 -5 -2 3 -1 0 -2 0
20 11 13 10 1 4 10 3 5 10 10 10 0 -1 -2 0 0 0
public class max_length_subsquence {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
while(true){
int sum;
int lefttemp;
int left;
int right;
int max;
int n=cin.nextInt();
if (n==0) break;
int []s=new int[n];
for (int i=0;imax){
max=sum;
left=lefttemp;
right=s[i];
}
}
if (max<0){
System.out.println(0+" "+s[0]+" "+s[n-1]);
}else
System.out.println(max+" "+left+" "+right);
}
}
}
测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接连通的两个城镇的编号。为简单起见,城镇从1到N编号。
注意:两个城市之间可以有多条道路相通,也就是说
3 3
1 2
1 2
2 1
这种输入也是合法的
当N为0时,输入结束,该用例不被处理。
对每个测试用例,在1行里输出最少还需要建设的道路数目。
4 2 1 3 4 3 3 3 1 2 1 3 2 3 5 2 1 2 3 5 999 0 0
1 0 2 998
public class changtong_2005 {
static int []pre;
public static int find(int i){
int j=i,temp;
while(pre[i]!=i){
i=pre[i];
}
while(j!=i){
temp=pre[j];
pre[j]=i;
j=temp;
}
return i;
}
public static void merge(int c,int d){
int t1=find(c);
int t2=find(d);
if (t1!=t2)
pre[t1]=t2;
return;
}
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
while(true){
int n=cin.nextInt();//城市
if (n==0) break;
int m=cin.nextInt();//道路
pre=new int[n+1];
for (int i=1;i<=n;i++)
pre[i]=i;
for (int i=1;i<=m;i++){
int c=cin.nextInt();
int d=cin.nextInt();
merge(c,d);//并查集处理
}
Setset=new HashSet();
for (int i=1;i<=n;i++)
{
set.add(find(i));
}
System.out.println(set.size()-1);//现在有多少类,相关类-1就是最少需要添加的桥梁
}
cin.close();
}
}
测试输入的第一行给出记录的总天数N ( N> 0 ),下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M (M > 0 ),下面是M行,每行的格式为
证件号码 签到时间 签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,且没有多人同时签到或者签离的情况。
3 1 ME3021112225321 00:00:00 23:59:59 2 EE301218 08:05:35 20:56:35 MA301134 12:35:45 21:40:42 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40
ME3021112225321 ME3021112225321 EE301218 MA301134 SC3021234 CS301133
class door{
String passsword;//证件号
int hour;//小时
int minute;//分钟
int second;//秒钟
}
class mycmp implements Comparator{//优先顺序小时,分钟,秒钟,从小到大
public int compare(door A,door B){
if (A.hour-B.hour!=0)
return A.hour-B.hour;
else
if (A.minute-B.minute!=0)
return A.minute-B.minute;
else
return A.second-B.second;
}
}
public class opendoor {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
while(n--!=0){
int m=cin.nextInt();
door []d=new door[m];
door []d2=new door[m];//离开时间
int i=0;
while(i
测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N < 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考号的升序输出。
4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0
3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20
class student{
public student(String name, int sum) {
this.name=name;
grade=sum;
}
String name;
int grade;
}
class mycmp2 implements Comparator{
@Override
public int compare(student a, student b){
if (a.grade!=b.grade)//从大到小排序
return b.grade-a.grade;
else
return a.name.compareTo(b.name);
}
}
public class rank {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
while(true){
int n=cin.nextInt();//考生人数
if (n==0)
break;
int m=cin.nextInt();//考题数
int g=cin.nextInt();//分数线
Listlist=new ArrayList();
int i=1;
Mapmap=new HashMap();
while(i<=m){
int c=cin.nextInt();
map.put(i, c);
i++;
}
while(n--!=0){
String name=cin.next();//读入学号
int k=cin.nextInt();
int sum=0;
while(k--!=0){
sum=sum+map.get(cin.nextInt());
}
if (sum>=g)//如果大于分数线,加入进入list
list.add(new student(name,sum));
}
System.out.println(list.size());
Collections.sort(list,new mycmp2());
for (int j=0;j