import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int seq = Integer.parseInt(br.readLine());
while (seq > 0) {
String answer = br.readLine();
int length = answer.length();
int[] r = new int[length];
int cnt = 1;
for (int i = 0; i < length;i++) {
char c = answer.charAt(i);
if (c == 'X') {
r[i] = 0;
cnt = 1;
} else {
r[i] = cnt;
cnt ++;
}
}
System.out.println(calc(r));
seq--;
}
br.close();
}
private static String calc(int[] numbers) {
int result = 0;
for (int i : numbers) {
result += i;
}
return String.valueOf(result);
}
}
網頁
BloggerAds 廣告
標籤
- Java (96)
- Android (27)
- 演算法 (21)
- c++ (19)
- JavaScript (7)
- OpenMp (6)
- Design Pattern (4)
- 日文歌曲 (4)
- 資料結構 (4)
- Foundation Knowledge Of Programming (3)
- QUT (2)
- CodingHomeWork (1)
- Database (1)
- 英文歌詞 (1)
搜尋此網誌
2017年3月11日 星期六
Uva 1585
2017年3月6日 星期一
Uva-1225
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
int round = Integer.parseInt(reader.readLine());
int[] ns = new int[round];
for (int i = 0; i < round; i++) {
ns[i] = Integer.parseInt(reader.readLine());
}
for (int n : ns) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= n; i++) {
sb.append(i);
}
int strLn = sb.length();
int[] answer = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (int j = 0; j < strLn; j++) {
int num = Character.getNumericValue(sb.charAt(j));
answer[num] += 1;
}
for (int k = 0; k < answer.length; k++) {
if (k == 9) {
System.out.print(answer[k]);
} else {
System.out.print(answer[k] + " ");
}
}
System.out.println();
}
reader.close();
}
}
訂閱:
文章 (Atom)
我的網誌清單
標籤
日文歌曲
(4)
股市
(7)
股票
(9)
英文歌詞
(1)
時事
(1)
硬體(hardware)
(1)
資料結構
(4)
演算法
(21)
數學(Math)
(4)
ACM
(3)
ajax
(7)
algorithms
(1)
Android
(27)
Blog Notes(部落格記事)
(6)
C
(9)
c++
(19)
CodingHomeWork
(1)
Database
(1)
Design Pattern
(4)
Foundation Knowledge Of Programming
(3)
GWT
(1)
How
(2)
J2EE
(1)
Java
(96)
Java語言
(4)
JavaScript
(7)
Leetcode
(4)
LOL
(1)
OpenMp
(6)
QUT
(2)
Uva
(2)
Yahoo知識問答
(11)