• 质数串


    多少个非空连续子串是质数串!!!!!~~~~以为是各种组合 记一条审题不清晰
    看了一篇博客才知道 wc https://www.cnblogs.com/bxd123/p/10658075.html
    (一拿到题感觉是dp 因为之前做过这种类似的字符dp 但是想不出来状态转移)我也觉得要动归 就是不知道怎么写
    题目暗示了质数串的条件非常严苛 所以可以枚举10000里面的答案
    很快发现只有
    2 3 5 7 23 37 53 73 373 (也就是仅有这种组合而已)

    import java.util.*;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		while (sc.hasNext()) {
    			int n = sc.nextInt();
    			while (n-- > 0) {
    				int lent = sc.nextInt();
    				String s = sc.next() + "X" + "X";
    				int count = 0;
    				for (int i = 0; i < lent; i++) {
    					if (s.charAt(i) == '2')
    						count++;
    					if (s.charAt(i) == '3')
    						count++;
    					if (s.charAt(i) == '5')
    						count++;
    					if (s.charAt(i) == '7')
    						count++;
    					if (s.charAt(i) == '2' && s.charAt(i + 1) == '3')
    						count++;
    					if (s.charAt(i) == '3' && s.charAt(i + 1) == '7')
    						count++;
    					if (s.charAt(i) == '5' && s.charAt(i + 1) == '3')
    						count++;
    					if (s.charAt(i) == '7' && s.charAt(i + 1) == '3')
    						count++;
    					if (s.charAt(i) == '3' && s.charAt(i + 1) == '7' && s.charAt(i + 2) == '3')
    						count++;
    				}
    				System.out.println(count);
    			}
    		}
    	}
    }
    
  • 相关阅读:
    Python open 读和写
    Sublime Text的使用
    解决MySQL Workbench导出乱码问题
    统计学(一)
    pymysql使用(二)
    使用pymysql(使用一)
    2个Excel表格核对技巧
    用Python读写Excel文件的方式比较
    从零上手Python关键代码
    php面试
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150148.html
Copyright © 2020-2023  润新知