zoukankan      html  css  js  c++  java
  • 质数串

    多少个非空连续子串是质数串!!!!!~~~~以为是各种组合 记一条审题不清晰
    看了一篇博客才知道 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);
    			}
    		}
    	}
    }
    
  • 相关阅读:
    iOS 绕过https证书验证 请求数据
    RN import ** from ** 用法
    蓝牙开发笔记
    golang笔记
    python3 md5
    python3 zip压缩
    nginx应用
    zipimport.ZipImportError: can't find module 'encodings'
    python3 模块安装列表
    cmd笔记
  • 原文地址:https://www.cnblogs.com/cznczai/p/11150148.html
Copyright © 2011-2022 走看看