-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_intern
167 lines (148 loc) · 3.75 KB
/
doc_intern
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author saksh
*/
import java.io.*;
class nb1 {
void sort(String a[],int h)
{
for(int i=0;i<h;i++)
{
for(int j=0;j<h-i-1;j++)
{
String s=a[j];
String s1=s.substring(0,s.lastIndexOf(' '));
int c=Integer.parseInt(s.substring(s.lastIndexOf(' ')+1));
String a1=s.substring(0,s.indexOf(' '));
double cg1=Double.parseDouble(s1.substring(s1.indexOf(' ')+1));
String z=a[j+1].substring(0,a[j+1].lastIndexOf(' '));
String xx=z.substring(0,z.indexOf(' '));
double cg=Double.parseDouble(z.substring(z.indexOf(' ')+1));
int m=Integer.parseInt(a[j+1].substring(a[j+1].lastIndexOf(' ')+1));
if(cg>cg1)
{
String t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
else if(cg==cg1&&c==m&&(a1.equals(xx)==false))
{
if(a1.compareTo(xx)>0)
{
String t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
else if(cg==cg1&&c!=m&&(a1.equals(xx)==true))
{
if(m<c)
{
String t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
}
void display(String a[],int j)
{
if(a[0]==null)
System.out.println("EMPTY");
else
{
for(int i=0;i<j;i++)
{
System.out.println(a[i].substring(0,a[i].indexOf(' ')));
}
}
}
int fill(String a[],String b[],int h)
{
int hh=h;
for(int i=0;i<a.length;i++)
{
if(a[i]!=null)
b[hh++]=a[i];
}
return hh;
}
void g(String a[])
{
int c=-1;
String a1="";
double cg1=-0.0;
int q=0;
for(int i=0;i<a.length;i++)
{
if(a[i]!=null)
{
String z=a[i].substring(0,a[i].lastIndexOf(' '));
String xx=z.substring(0,z.indexOf(' '));
double cg=Double.parseDouble(z.substring(z.indexOf(' ')+1));
int m=Integer.parseInt(a[i].substring(a[i].lastIndexOf(' ')+1));
if(cg>cg1)
{
q=i;
cg1=cg;
c=m;
a1=xx;
}
else if(cg==cg1&&c==m&&(a1.equals(xx)==false))
{
if(a1.compareTo(xx)>0)
{
q=i;
cg1=cg;
c=m;
a1=xx;
}
}
else if(cg==cg1&&c!=m&&(a1.equals(xx)==true))
{
if(m<c)
{
q=i;
cg1=cg;
c=m;
a1=xx;
}
}
}
}
a[q]=null;
}
public static void main(String args[])throws IOException
{
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
nb1 o=new nb1();
int i=Integer.parseInt(inp.readLine());String f="";
int j=0;
String b[]=new String[i];
j=0;
int c=0;
String b1[]=new String[i];int n=0;
while(i!=0)
{
String s=inp.readLine();
if(s.contains("ENTER")==true)
{
b[j++]=s.substring(s.indexOf(' ')+1);
}
else
{
o.g(b);
}
f=s;i--;
}
c=o.fill(b, b1, c);
o.sort(b1,c);
o.display(b1,c);
}
}