-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas.java
More file actions
129 lines (83 loc) · 2.34 KB
/
Copy pathas.java
File metadata and controls
129 lines (83 loc) · 2.34 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.sort;
/**
* @author cx
* @date 2018/8/28 20:00
* @description
*/
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
public class as{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//String a = scanner.next();
int a = Integer.parseInt(scanner.next());
int b = Integer.parseInt(scanner.next());
//一提
//System.out.println(getNum(a));
// 二题
// List c = fanzhuan(a,b);
// for (int i = 0; i < c.size(); i++) {
// System.out.print(c.get(i));
// }
}
//再一个题
//又一个题
public static List fanzhuan(String a,int b){
int len = a.length();
Stack str = new Stack();
List finalStr = new ArrayList();
int c = len/(3*b)+1;
for (int i = 0; i < c; i++) {
for (int j = i*b*3; j < i*b*3+b&&j<len; j++) {
str.push(a.charAt(j));
}
while (!str.isEmpty()){
finalStr.add(str.pop());
}
for (int j = i*b*3+b; j < i*b*3+3*b&&j<len; j++) {
finalStr.add(a.charAt(j));
}
}
return finalStr;
}
//一个题
public static int getNum(String a){
int num=0;
int l=a.length()-1;
int r=a.length()-1;
for (; l>=0 ; ) {
//System.out.println(l+"两头"+r);
if (charToInt(a.charAt(r))%3==0){
num++;
r--;
l--;
continue;
}else {
l--;
if (charsToInt(a,l,r)%3==0){
//System.out.println(l+"被整除"+r);
num++;
r=l-1;
l=l-1;
}else {
//System.out.println(l+"没被整除"+r);
continue;
}
}
}
return num;
}
public static int charsToInt(String a,int l,int r){
int num=0;
//System.out.println(l+"=============="+r);
for (int i = r,j = 1; i >= l; i--,j*=10) {
num+=charToInt(a.charAt(i))*j;
}
return num;
}
public static int charToInt(char a){
return (int)a-'0';
}
}