-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompresie de date.java
More file actions
48 lines (48 loc) · 1.62 KB
/
Compresie de date.java
File metadata and controls
48 lines (48 loc) · 1.62 KB
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
import java.util.*;
public class Eccpr{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int cnt=0;
String theStr="",num;
String[] strArr;
int[] intArr;
for(int j=0;j<n;j++){
theStr = sc.next();
strArr = theStr.split(",");
intArr = new int[strArr.length];
for (int i = 0; i < strArr.length; i++) {
num = strArr[i];
intArr[i] = Integer.parseInt(num);
}
theStr="";
for(int i=intArr.length-1;i>=0;i--){
if(intArr[i]!=0&&cnt==0){
theStr+=Integer.toString(intArr[i]);
theStr+=",";
}else if(intArr[i]==0){
cnt++;
}else if(intArr[i]!=0&&cnt!=0){
theStr+=")";
theStr+=Integer.toString(cnt);
theStr+=",";
if(intArr[i]<9){
theStr+=Integer.toString(intArr[i]);
}else{
while(intArr[i]>0){
theStr+=Integer.toString(intArr[i]%10);
intArr[i]/=10;
}
}
theStr+="(";
theStr+=",";
cnt=0;
}
}
for(int i=theStr.length()-2;i>=0;i--){
System.out.print(theStr.charAt(i));
}
System.out.println();
}
}
}