本帖最后由 萌墨 于 2021-8-28 21:28 编辑
不能惯着mjj,我用Java写
- import java.util.*;
- public class Statistics {
- public static void main(String[] args) {
- Collection<Character> collection = new ArrayList<Character>(Arrays.asList('a', 'a', 'A', 'a', 'a', 'a', 'A', 'a'));
- int countA = 0;
- int counta = 0;
- Map<String, Integer> map = new HashMap<>();
- for (Character c :
- collection) {
- if (c.equals('A')) {
- countA++;
- counta = 0;
- } else {
- if (countA==0){
- continue;
- }
- counta++;
- map.put("第" + countA + "个A后有", counta);
- }
- }
- for (String key :
- map.keySet()) {
- System.out.println(key + ":" + map.get(key));
- }
- }
- }
复制代码
|