Skip to content

Commit 27d9f1e

Browse files
committed
Update 1700B-PalindromicNumbers.cpp
1 parent 29370f1 commit 27d9f1e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

1700B-PalindromicNumbers.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
#include <cstdio>
2-
typedef long long ll;
1+
#include <iostream>
32

43
int main(){
54

6-
ll t; scanf("%lld", &t);
5+
long t; std::cin >> t;
76
while(t--){
8-
int len; ll n; scanf("%d %lld", &len, &n);
9-
ll res(0), tmp(n);
10-
while(tmp){res = 10 * res + (tmp % 10); tmp /= 10;}
11-
while(len--){res *= 10;}
12-
printf("%lld\n", res);
7+
long len; std::cin >> len;
8+
std::string s; std::cin >> s;
9+
10+
std::string t(s.size(), '_');
11+
if(s[0] != '9'){for(long p = 0; p < s.size(); p++){t[p] = '0' + ('9' - s[p]);}}
12+
else{
13+
int carry(0);
14+
for(long p = s.size() - 1; p >= 0; p--){
15+
int a = 1 - carry;
16+
int b = s[p] - '0';
17+
int diff = a - b;
18+
if(diff < 0){carry = 1; diff += 10;}
19+
else{carry = 0;}
20+
t[p] = (char)(diff + '0');
21+
}
22+
}
23+
24+
std::cout << t << std::endl;
1325
}
1426

1527
}

0 commit comments

Comments
 (0)