Skip to content

Commit 25c672a

Browse files
committed
update
1 parent f619939 commit 25c672a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Time: 265 ms
2+
// Memory: 1300 KB
3+
// Greedy.
4+
// T:O(n), S:O(1)
5+
//
6+
import java.util.Scanner;
7+
8+
public class Codeforces_2093B_Expensive_Number {
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int t = sc.nextInt();
12+
for (int i = 0; i < t; i++) {
13+
String n = sc.next();
14+
int lastNonZeroIndex = -1, countPrefixNonZero = 0, countSuffix = 0;
15+
for (int j = n.length() - 1; j >= 0; j--) {
16+
if (n.charAt(j) != '0') {
17+
lastNonZeroIndex = j;
18+
break;
19+
}
20+
countSuffix++;
21+
}
22+
for (int j = 0; j < lastNonZeroIndex; j++) {
23+
if (n.charAt(j) != '0') {
24+
countPrefixNonZero++;
25+
}
26+
}
27+
28+
System.out.println(countPrefixNonZero + countSuffix);
29+
}
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Runtime 0 ms Beats 100.00%
2+
// Memory 41.34 MB Beats 100.00%
3+
// .
4+
// T:O(logn), S:O(1)
5+
//
6+
class Solution {
7+
public boolean checkDivisibility(int n) {
8+
int sum1 = 0, sum2 = 1, n1 = n;
9+
while (n1 > 0) {
10+
sum1 += n1 % 10;
11+
n1 /= 10;
12+
}
13+
n1 = n;
14+
while (n1 > 0) {
15+
sum2 *= n1 % 10;
16+
n1 /= 10;
17+
}
18+
19+
return n % (sum1 + sum2) == 0;
20+
}
21+
}

0 commit comments

Comments
 (0)