1- import java .util .*;
2- public class IPA7 {
3- public static void main (String [] args ) {
4- Scanner sc = new Scanner (System .in );
5- Sim [] s = new Sim [5 ];
6- for (int i = 0 ; i < s .length ; i ++) {
7- int a = sc .nextInt ();sc .nextLine ();
8- String b = sc .nextLine ();
9- double c = sc .nextDouble ();
10- double d = sc .nextDouble ();sc .nextLine ();
11- String e = sc .nextLine ();
12-
13- s [i ]=new Sim (a ,b ,c ,d ,e );
14- }
15- String circle1 = sc .nextLine ();
16- String circle2 = sc .nextLine ();
17- Sim [] arr = transfer (s ,circle1 ,circle2 );
18- if (arr !=null )
19- {
20- for (int i = arr .length -1 ; i >=0 ; i --) {
21- System .out .println (arr [i ].getSimId ()+" " +arr [i ].getCustomerName ()+" " +arr [i ].circle +" " +arr [i ].getRatePerSecond ());
22- }
23- }
24- }
25- public static Sim [] transfer (Sim []s , String c1 , String c2 )
26- {
27- Sim [] details = new Sim [0 ];
28- for (int i =0 ; i <s .length ; i ++)
29- {
30- if (s [i ].getCircle ().equalsIgnoreCase (c1 ))
31- {
32- details = Arrays .copyOf (details ,details .length +1 );
33- s [i ].circle =c2 ;
34- details [details .length -1 ]=s [i ];
35- }
36- }
37- for (int i = 0 ; i < details .length ; i ++) {
38- for (int j = i +1 ; j < details .length ; j ++) {
39- if (details [i ].getRatePerSecond ()>details [j ].getRatePerSecond ())
40- {
41- Sim k = details [i ];
42- details [i ]=details [j ];
43- details [j ]=k ;
44- }
45- }
46- }
47- if (details .length >0 )
48- {
49- return details ;
50- }
51- else
52- {
53- return null ;
54- }
55- }
56- }
57- class Sim
58- {
59- int simId ;
60- String customerName , circle ;
61- double balance , ratePerSecond ;
62-
63- public Sim (int simId , String customerName , double balance , double ratePerSecond , String circle )
64- {
65- this .simId = simId ;
66- this .customerName = customerName ;
67- this .balance = balance ;
68- this .ratePerSecond = ratePerSecond ;
69- this .circle = circle ;
70- }
71-
72- public int getSimId ()
73- {
74- return simId ;
75- }
76- public void setSimId (int simId )
77- {
78- this .simId = simId ;
79- }
80- public String getCustomerName ()
81- {
82- return customerName ;
83- }
84- public void setCustomerName (String customerName )
85- {
86- this .customerName = customerName ;
87- }
88- public double getBalance ()
89- {
90- return balance ;
91- }
92- public void setBalance (double balance )
93- {
94- this .balance = balance ;
95- }
96- public double getRatePerSecond ()
97- {
98- return ratePerSecond ;
99- }
100- public void setRatePerSecond (double ratePerSecond )
101- {
102- this .ratePerSecond = ratePerSecond ;
103- }
104- public String getCircle ()
105- {
106- return circle ;
107- }
108- public void setCircle (String circle )
109- {
110- this .circle = circle ;
111- }
1+ package IPA7 ;
2+ import java .util .*;
3+ public class IPA7 {
4+ public static void main (String [] args ) {
5+ Scanner sc = new Scanner (System .in );
6+ Sim [] s = new Sim [5 ];
7+ for (int i = 0 ; i < s .length ; i ++) {
8+ int a = sc .nextInt ();sc .nextLine ();
9+ String b = sc .nextLine ();
10+ double c = sc .nextDouble ();
11+ double d = sc .nextDouble ();sc .nextLine ();
12+ String e = sc .nextLine ();
13+
14+ s [i ]=new Sim (a ,b ,c ,d ,e );
15+ }
16+ String circle1 = sc .nextLine ();
17+ String circle2 = sc .nextLine ();
18+ Sim [] arr = transfer (s ,circle1 ,circle2 );
19+ if (arr !=null )
20+ {
21+ for (int i = arr .length -1 ; i >=0 ; i --) {
22+ System .out .println (arr [i ].getSimId ()+" " +arr [i ].getCustomerName ()+" " +arr [i ].circle +" " +arr [i ].getRatePerSecond ());
23+ }
24+ }
25+ }
26+ public static Sim [] transfer (Sim []s , String c1 , String c2 )
27+ {
28+ Sim [] details = new Sim [0 ];
29+ for (int i =0 ; i <s .length ; i ++)
30+ {
31+ if (s [i ].getCircle ().equalsIgnoreCase (c1 ))
32+ {
33+ details = Arrays .copyOf (details ,details .length +1 );
34+ s [i ].circle =c2 ;
35+ details [details .length -1 ]=s [i ];
36+ }
37+ }
38+ for (int i = 0 ; i < details .length ; i ++) {
39+ for (int j = i +1 ; j < details .length ; j ++) {
40+ if (details [i ].getRatePerSecond ()>details [j ].getRatePerSecond ())
41+ {
42+ Sim k = details [i ];
43+ details [i ]=details [j ];
44+ details [j ]=k ;
45+ }
46+ }
47+ }
48+ if (details .length >0 )
49+ {
50+ return details ;
51+ }
52+ else
53+ {
54+ return null ;
55+ }
56+ }
57+ }
58+ class Sim
59+ {
60+ int simId ;
61+ String customerName , circle ;
62+ double balance , ratePerSecond ;
63+
64+ public Sim (int simId , String customerName , double balance , double ratePerSecond , String circle )
65+ {
66+ this .simId = simId ;
67+ this .customerName = customerName ;
68+ this .balance = balance ;
69+ this .ratePerSecond = ratePerSecond ;
70+ this .circle = circle ;
71+ }
72+
73+ public int getSimId ()
74+ {
75+ return simId ;
76+ }
77+ public void setSimId (int simId )
78+ {
79+ this .simId = simId ;
80+ }
81+ public String getCustomerName ()
82+ {
83+ return customerName ;
84+ }
85+ public void setCustomerName (String customerName )
86+ {
87+ this .customerName = customerName ;
88+ }
89+ public double getBalance ()
90+ {
91+ return balance ;
92+ }
93+ public void setBalance (double balance )
94+ {
95+ this .balance = balance ;
96+ }
97+ public double getRatePerSecond ()
98+ {
99+ return ratePerSecond ;
100+ }
101+ public void setRatePerSecond (double ratePerSecond )
102+ {
103+ this .ratePerSecond = ratePerSecond ;
104+ }
105+ public String getCircle ()
106+ {
107+ return circle ;
108+ }
109+ public void setCircle (String circle )
110+ {
111+ this .circle = circle ;
112+ }
112113}
0 commit comments