1164: 通话记录

来源:互联网 发布:央行网络支付新规 编辑:程序博客网 时间:2024/05/16 13:46

题目

Description

使用3个队列,分别保留手机上最近10个,(0)未接来电、(1)已接来电、(2)已拨电话。

Input

全部通话记录,每行一条记录。

每条记录包含两个数字,第一个数代表记录类型,第二个数代表手机号码。

Output

分3列输出未接来电、已接来电、已拨电话。

列之间用空格分割,后接电话在最先输出,不足10条用0占位。

Sample Input

2 18270477699
1 10149800116
0 19906559817
1 16209018105
1 16804212234
2 19289130583
1 17982711123
0 10897630486
1 11860787674
0 15192777554
Sample Output

15192777554 11860787674 19289130583
10897630486 17982711123 18270477699
19906559817 16804212234 0
0 16209018105 0
0 10149800116 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0


代码块

import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cn = new Scanner(System.in);        Phone[] ph = new Phone[100];//定义一个通讯录类数组        int i =0;        while(cn.hasNext()){//对每次进行输入的数,存入到通讯录类中去            int type = cn.nextInt();            String str = cn.next();            ph[i] = new Phone(type,str);            i++;        }        String[][] sh = new String[10][3];//先对,自己定义的数组,进行初始化0        for(int z =0;z<10;z++){            for(int y = 0;y<3;y++){                sh[z][y] = "0";            }        }        int j=0,l=0,h=0;        for(int k= i-1;k>=0;k--){//因为是要先更新最新的通讯录,放在最前面,            if(ph[k].getType()==0){//判断,并进行对应的数组存入                sh[j][0] = ph[k].getNumber();                j++;            }            if(ph[k].getType()==1){                sh[l][1] = ph[k].getNumber();                l++;            }            if(ph[k].getType()==2){                sh[h][2] = ph[k].getNumber();                h++;            }        }        for(int z =0 ;z<10;z++){//进行输入格式的,细心输出,即可ac            for(int y = 0;y<3;y++){                if(y<2) System.out.print(sh[z][y]+" ");                else System.out.print(sh[z][y]);            }            System.out.println();        }        cn.close();    }}//自己定义的一个通讯录的类,用来存储电话号码等class Phone {    private int type;    private String number;    public Phone(int type,String number){        this.type = type;        this.number = number;    }    public int getType(){        return this.type;    }    public String getNumber(){        return this.number;    }}