-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathincantatii.cpp
45 lines (41 loc) · 977 Bytes
/
incantatii.cpp
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
# include <fstream>
# include <algorithm>
# include <cstring>
# define NR 1000005
# define sigma 53
using namespace std;
ifstream f("incantatii.in");
ofstream g("incantatii.out");
int i,j,n,m,l,R;
long long P[15], v[NR], nr;
char s[15];
void puteri () {
P[0]=1;
P[1]=sigma;
for (i=2; i<=10; ++i)
P[i]=P[i-1]*sigma;
}
int main ()
{
f>>n; f.get(); puteri ();
for (i=1; i<=n; ++i) {
f.getline (s+1, 10); nr=0;
for (j=1; j<=9; ++j) {
if (s[j]=='\0') break;
if ('A'<=s[j] && s[j]<='Z') nr+=(s[j]-'A'+1)*P[9-j];
else nr+=(s[j]-'a'+27)*P[9-j];
}
v[i]=nr;
}
sort (v+1, v+n+1);
for (i=1; i<=n; ++i) {
for (j=9; j>=0; --j)
if (v[i]>=P[j]) {
R=v[i]/P[j]; v[i]-=R*P[j];
if (R<=26) g<<(char)('A'+R-1);
else g<<(char)('a'+R-27);
}
g<<"\n";
}
return 0;
}