题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Stream.*;


public class Main {
    public static void main(String[] args) throws IOException {

        //testCompletePack();
        testTh();
    }

    private static void testTh() throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = bf.readLine()) != null) {
            String regA = "[a-z|A-Z]";
            String reg1 = "\\d";
            String regB = " ";
            int countA = 0;
            int count1 = 0;
            int countB = 0;
            int countAn = 0;
            char[] chars = str.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                String temp = chars[i] + "";
                if (temp.matches(regA)) {
                    countA++;
                } else if (temp.matches(reg1)) {
                    count1++;
                } else if (temp.matches(regB)) {
                    countB++;
                } else {
                    countAn++;
                }
            }
            System.out.println(countA);
            System.out.println(countB);
            System.out.println(count1);
            System.out.println(countAn);

        }

    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务