1
- #include < bits/stdc++.h>
1
+ #include < bits/stdc++.h>
2
+
2
3
using namespace std ;
3
- #define FOR (i,a,b ) for (int i = (a); i <= (b); ++i)
4
- #define FORD (i,a,b ) for (int i = (a); i >= (b); --i)
5
- #define TRAV (x,T ) for (auto & (x): (T))
6
- #define ALL (x ) x.begin(), x.end()
7
- #define TAB (x,n ) (x)+1 , (x)+((n)+1 )
8
- #define sz (x ) (int )(x).size()
9
- #define pb push_back
10
- #define pf push_front
11
- #define st first
12
- #define nd second
13
- typedef long long ll;
14
- typedef long double ld;
15
- typedef pair<int , int > pii;
16
- typedef pair<ll, ll> pll;
17
- typedef vector<int > vi;
18
4
19
- const int BASE = 1000000000 ; /* podstawa */
20
- const int DIGS = 9 ; /* liczba cyfr dziesietnych kazdej cyfry w zapisie
21
- przy powyzszej podstawie */
22
- const int LEN = 1000 ; /* stala dlugosc liczb */
5
+ const int BASE = 1000000000 ; // podstawa
6
+ const int DIGS =
7
+ 9 ; // liczba cyfr dziesietnych kazdej cyfry w zapisie powyzszej podstawie
8
+ const int LEN = 1000 ; // stala dlugosc liczb
23
9
24
10
struct liczba {
25
- int t[LEN];
26
- int l; /* faktyczna dlugosc liczby */
11
+ int t[LEN];
12
+ int l; /* faktyczna dlugosc liczby */
27
13
};
28
14
29
15
void wypisz (liczba x) {
30
- printf (" %d" , x.t [x.l - 1 ]);
31
- for (int i = x.l - 2 ; i >= 0 ; i--)
32
- printf (" %0*d" , DIGS, x.t [i]);
16
+ printf (" %d" , x.t [x.l - 1 ]);
17
+ for (int i = x.l - 2 ; i >= 0 ; i--)
18
+ printf (" %0*d" , DIGS, x.t [i]);
33
19
}
34
20
35
21
void czytaj (liczba &x) {
36
- char s[LEN * DIGS + 1 ];
37
- scanf (" %s" , s); /* czytamy lancuch - zakladamy, ze nie ma zer wiodacych */
38
- /* Ustalamy dlugosc liczby */
39
- int j = strlen (s); /* pozycja w lancuchu s */
40
- if (j % DIGS == 0 )
41
- x.l = j / DIGS;
42
- else
43
- x.l = j / DIGS + 1 ;
44
- j--;
45
- for (int i = 0 ; i < x.l ; i++)
46
- {
47
- /* ustalamy i-ta cyfre */
48
- x.t [i] = 0 ;
49
- for (int k = max (0 , j - DIGS + 1 ); k <= j; k++)
50
- x.t [i] = 10 * x.t [i] + (s[k] - ' 0' );
51
- j -= DIGS;
52
- }
22
+ char s[LEN * DIGS + 1 ];
23
+ scanf (" %s" , s); /* czytamy lancuch - zakladamy, ze nie ma zer wiodacych */
24
+ /* Ustalamy dlugosc liczby */
25
+ int j = strlen (s); /* pozycja w lancuchu s */
26
+ if (j % DIGS == 0 )
27
+ x.l = j / DIGS;
28
+ else
29
+ x.l = j / DIGS + 1 ;
30
+ j--;
31
+ for (int i = 0 ; i < x.l ; i++) {
32
+ /* ustalamy i-ta cyfre */
33
+ x.t [i] = 0 ;
34
+ for (int k = max (0 , j - DIGS + 1 ); k <= j; k++)
35
+ x.t [i] = 10 * x.t [i] + (s[k] - ' 0' );
36
+ j -= DIGS;
37
+ }
53
38
}
54
39
55
- liczba operator + (liczba x, liczba y) {
56
- liczba z; /* wynik */
57
- /* Do dlugosci mniejszej z liczb: */
58
- z.l = min (x.l , y.l );
59
- int c = 0 ; /* na poczatek zerowy bit przeniesienia */
60
- for (int i = 0 ; i < z.l ; i++)
61
- {
62
- z.t [i] = (x.t [i] + y.t [i] + c) % BASE;
63
- c = (x.t [i] + y.t [i] + c) / BASE;
64
- }
65
- /* Jezeli liczba x jest dluzsza: */
66
- while (z.l < x.l )
67
- {
68
- z.t [z.l ] = (x.t [z.l ] + c) % BASE;
69
- c = (x.t [z.l ] + c) / BASE;
70
- z.l ++;
71
- }
72
- /* Jezeli liczba y jest dluzsza: */
73
- while (z.l < y.l )
74
- {
75
- z.t [z.l ] = (y.t [z.l ] + c) % BASE;
76
- c = (y.t [z.l ] + c) / BASE;
77
- z.l ++;
78
- }
79
- /* Jezeli pozostalo jakies przeniesienie (to c=1): */
80
- if (c > 0 )
81
- {
82
- z.t [z.l ] = c;
83
- z.l ++;
84
- }
85
- return z;
40
+ liczba operator +(liczba x, liczba y) {
41
+ liczba z; /* wynik */
42
+ /* Do dlugosci mniejszej z liczb: */
43
+ z.l = min (x.l , y.l );
44
+ int c = 0 ; /* na poczatek zerowy bit przeniesienia */
45
+ for (int i = 0 ; i < z.l ; i++) {
46
+ z.t [i] = (x.t [i] + y.t [i] + c) % BASE;
47
+ c = (x.t [i] + y.t [i] + c) / BASE;
48
+ }
49
+ /* Jezeli liczba x jest dluzsza: */
50
+ while (z.l < x.l ) {
51
+ z.t [z.l ] = (x.t [z.l ] + c) % BASE;
52
+ c = (x.t [z.l ] + c) / BASE;
53
+ z.l ++;
54
+ }
55
+ /* Jezeli liczba y jest dluzsza: */
56
+ while (z.l < y.l ) {
57
+ z.t [z.l ] = (y.t [z.l ] + c) % BASE;
58
+ c = (y.t [z.l ] + c) / BASE;
59
+ z.l ++;
60
+ }
61
+ /* Jezeli pozostalo jakies przeniesienie (to c=1): */
62
+ if (c > 0 ) {
63
+ z.t [z.l ] = c;
64
+ z.l ++;
65
+ }
66
+ return z;
86
67
}
87
68
88
- liczba operator - (liczba x, liczba y) {
89
- liczba z; /* wynik */
90
- z.l = x.l ;
91
- int c = 0 ; /* nie ma pozyczki na poczatek */
92
- for (int i = 0 ; i < x.l ; i++)
93
- {
94
- if (i < y.l ) /* odjemnik sie jeszcze nie skonczyl */
95
- z.t [i] = x.t [i] - y.t [i] + c;
96
- else /* odjemnik sie skonczyl */
97
- z.t [i] = x.t [i] + c;
98
- if (z.t [i] < 0 ) /* musimy pozyczyc */
99
- {
100
- z.t [i] += BASE;
101
- c = -1 ;
102
- }
103
- else
104
- c = 0 ;
105
- }
106
- /* Ucinamy ewentualne zera wiodace */
107
- while (z.l > 1 && z.t [z.l - 1 ] == 0 )
108
- z.l --;
109
- return z;
69
+ liczba operator -(liczba x, liczba y) {
70
+ liczba z; /* wynik */
71
+ z.l = x.l ;
72
+ int c = 0 ; /* nie ma pozyczki na poczatek */
73
+ for (int i = 0 ; i < x.l ; i++) {
74
+ if (i < y.l ) /* odjemnik sie jeszcze nie skonczyl */
75
+ z.t [i] = x.t [i] - y.t [i] + c;
76
+ else /* odjemnik sie skonczyl */
77
+ z.t [i] = x.t [i] + c;
78
+ if (z.t [i] < 0 ) /* musimy pozyczyc */
79
+ {
80
+ z.t [i] += BASE;
81
+ c = -1 ;
82
+ } else
83
+ c = 0 ;
84
+ }
85
+ /* Ucinamy ewentualne zera wiodace */
86
+ while (z.l > 1 && z.t [z.l - 1 ] == 0 )
87
+ z.l --;
88
+ return z;
110
89
}
111
90
112
- bool operator < (liczba x, liczba y) {
113
- if (x.l < y.l )
114
- return true ;
115
- if (x.l > y.l )
116
- return false ;
117
- int i = x.l - 1 ;
118
- while (i >= 0 && x.t [i] == y.t [i])
119
- i--;
120
- if (i < 0 )
121
- return false ;
122
- if (x.t [i] < y.t [i])
123
- return true ;
124
- return false ;
91
+ bool operator <(liczba x, liczba y) {
92
+ if (x.l < y.l )
93
+ return true ;
94
+ if (x.l > y.l )
95
+ return false ;
96
+ int i = x.l - 1 ;
97
+ while (i >= 0 && x.t [i] == y.t [i])
98
+ i--;
99
+ if (i < 0 )
100
+ return false ;
101
+ if (x.t [i] < y.t [i])
102
+ return true ;
103
+ return false ;
125
104
}
126
105
127
- bool operator > (liczba x, liczba y) {
128
- return y < x;
129
- }
106
+ bool operator >(liczba x, liczba y) { return y < x; }
130
107
131
- bool operator == (liczba x, liczba y) {
132
- return !(x < y) && !(y < x);
133
- }
108
+ bool operator ==(liczba x, liczba y) { return !(x < y) && !(y < x); }
134
109
135
110
/* Dla ulatwienia zalozmy, ze y nie jest zerem. */
136
- liczba operator * (liczba x, int y) {
137
- liczba z;
138
- z.l = x.l ;
139
- int c = 0 ;
140
- for (int i = 0 ; i < x.l ; i++)
141
- {
142
- z.t [i] = int (((long long )(x.t [i]) * y + c) % BASE);
143
- c = int (((long long )(x.t [i]) * y + c) / BASE);
144
- }
145
- while (c > 0 )
146
- {
147
- z.t [z.l ] = c % BASE;
148
- c /= BASE;
149
- z.l ++;
150
- }
151
- return z;
111
+ liczba operator *(liczba x, int y) {
112
+ liczba z;
113
+ z.l = x.l ;
114
+ int c = 0 ;
115
+ for (int i = 0 ; i < x.l ; i++) {
116
+ z.t [i] = int (((long long )(x.t [i]) * y + c) % BASE);
117
+ c = int (((long long )(x.t [i]) * y + c) / BASE);
118
+ }
119
+ while (c > 0 ) {
120
+ z.t [z.l ] = c % BASE;
121
+ c /= BASE;
122
+ z.l ++;
123
+ }
124
+ return z;
152
125
}
153
126
154
- liczba operator * (liczba x, liczba y) {
155
- liczba z;
156
- z.l = 1 ; z. t [ 0 ] = 0 ; /* z to początkowo 0 */
157
- for ( int i = 0 ; i < y. l ; i++)
158
- {
159
- liczba pom (x * y.t [i]);
160
- /* przesuwamy liczbe pom, dodajac i zer na koncu */
161
- for (int j = pom.l - 1 ; j >= 0 ; j--)
162
- pom.t [j + i] = pom.t [j];
163
- for (int j = 0 ; j < i; j++)
164
- pom.t [j] = 0 ;
165
- pom.l = pom.l + i;
166
- z = z + pom;
167
- }
168
- return z;
127
+ liczba operator *(liczba x, liczba y) {
128
+ liczba z;
129
+ z.l = 1 ;
130
+ z. t [ 0 ] = 0 ; /* z to początkowo 0 */
131
+ for ( int i = 0 ; i < y. l ; i++) {
132
+ liczba pom (x * y.t [i]);
133
+ /* przesuwamy liczbe pom, dodajac i zer na koncu */
134
+ for (int j = pom.l - 1 ; j >= 0 ; j--)
135
+ pom.t [j + i] = pom.t [j];
136
+ for (int j = 0 ; j < i; j++)
137
+ pom.t [j] = 0 ;
138
+ pom.l = pom.l + i;
139
+ z = z + pom;
140
+ }
141
+ return z;
169
142
}
170
143
171
- int operator % (liczba x, int y) {
172
- long long z = (long long )(x.t [x.l - 1 ]) % y;
173
- for (int i = x.l - 2 ; i >= 0 ; i--)
174
- z = (z * BASE + x.t [i]) % y;
175
- return int (z);
144
+ int operator %(liczba x, int y) {
145
+ long long z = (long long )(x.t [x.l - 1 ]) % y;
146
+ for (int i = x.l - 2 ; i >= 0 ; i--)
147
+ z = (z * BASE + x.t [i]) % y;
148
+ return int (z);
176
149
}
177
150
178
- liczba operator / (liczba x, int y) {
179
- liczba z;
180
- int c = 0 ; /* przeniesienie */
181
- z.l = x.l ;
182
- for (int i = x.l - 1 ; i >= 0 ; i--)
183
- {
184
- z.t [i] = int (((long long )(c) * BASE + (long long )x.t [i]) / y);
185
- c = int (((long long )(c) * BASE + (long long )x.t [i]) % y);
186
- }
187
- /* Usuwamy ewentualne nowopowstale zera wiodace */
188
- while (z.l > 1 && z.t [z.l - 1 ] == 0 )
189
- z.l --;
190
- return z;
151
+ liczba operator /(liczba x, int y) {
152
+ liczba z;
153
+ int c = 0 ; /* przeniesienie */
154
+ z.l = x.l ;
155
+ for (int i = x.l - 1 ; i >= 0 ; i--) {
156
+ z.t [i] = int (((long long )(c)*BASE + (long long )x.t [i]) / y);
157
+ c = int (((long long )(c)*BASE + (long long )x.t [i]) % y);
158
+ }
159
+ /* Usuwamy ewentualne nowopowstale zera wiodace */
160
+ while (z.l > 1 && z.t [z.l - 1 ] == 0 )
161
+ z.l --;
162
+ return z;
191
163
}
192
164
193
165
signed main () {
194
- ios_base::sync_with_stdio (0 );
195
- cin.tie (0 );
196
- liczba a, b;
197
- czytaj (a); czytaj (b);
198
- cout<<(a < b)<<" \n " ;
199
- return 0 ;
200
- }
166
+ ios_base::sync_with_stdio (0 );
167
+ cin.tie (0 );
168
+ liczba a, b;
169
+ czytaj (a);
170
+ czytaj (b);
171
+ cout << (a < b) << " \n " ;
172
+ return 0 ;
173
+ }
0 commit comments