Java程序练习-Mobile Number

描述
One day, an alpc found a modified telephone booklet in our laboratory recording almost all alpcs' mobile phone numbers. Now he asks you to verify the numbers.

We call the number of different digitals at the same position of two phone numbers: 'difference'.

Number 1: 1 3 6 0 0 0 0 0 0 0 0
Number 2: 1 4 6 0 0 0 0 0 0 0 1
Difference: 0+1+0+0+0+0+0+0+0+0+1 = 2

Search the booklet and find out the numbers between the difference A and B to the given correct phone numbers.

输入
The first line of the input is two integers: n and m. n is the numbers counted on the booklet, while m is the given correct phone numbers (0 < n ≤ 1000, 0 < m ≤ 200).

Then follow n lines. On each line is a phone number in the booklet which are all distinct. Then m lines, on each line there is a correct given phone number and difference A and B (0 ≤ A, B ≤ 11). Note: all the input phone numbers will be valid phone number: 11 digitals per number.

输出
For each given correct phone number, print "Number *:"(* should be replaced by the order this number shows up).

Then print all the within-difference number in the booklet. Ordered as the same as in the booklet.

Then follows a line printed "Total: *", * should be replaced by the total number of the within-difference numbers.

Then print a blank line after each given correct phone number.

样例输入
4 2
13600000000
13500000001
13700000001
15500000000
13600000000 1 1
13700000001 1 2
样例输出
Number 1:
Total: 0

Number 2:
13600000000
13500000001
Total: 2

参考代码

import java.util.*; public class Main { public final static int N = 11; public static void main(String[] args) throws Exception { Scanner cin = new Scanner(System.in); int size = cin.nextInt(),cases = cin.nextInt(); cin.nextLine(); String data[] = new String[size]; int i,j; for(i = 0;i < size;++ i){ data[i] = cin.nextLine(); } for(j = 1;j <= cases;++ j){ int total = 0; String ts = cin.next(); char ts2c[] = ts.toCharArray(); int ta = cin.nextInt(); int tb = cin.nextInt(); int temp; if(ta > tb){ temp = ta; ta = tb; tb = temp; } cin.nextLine(); System.out.println("Number "+j+":"); for(i = 0;i < size;++ i){ int diff = 0; char data2c[] = data[i].toCharArray(); for(int cp = 0;cp < N;++ cp){ if(ts2c[cp]!= data2c[cp]){ diff ++; } } if(diff >= ta && diff <= tb){ total ++; System.out.println(data[i]); } } System.out.println("Total: "+total); System.out.println(); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值