1 条题解
-
0
C :
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> int prime(int n) { int i; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) break; } if (i <= sqrt(n)) return 0; return 1; } int main() { int n, i, ok, flag, a; char s[101]; while (scanf("%d%*c", &n) != EOF, n) { while (n--) { gets(s); for (ok = flag = a = i = 0; s[i]; i++) { if (!isalnum(s[i])) { ok = 1; break; } if (isdigit(s[i])) { flag = 1; a = a * 10 + s[i] - '0'; } else { if (flag) { if (!prime(a)) { ok = 1; break; } flag = a = 0; } } } if (!prime(a)) ok = 1; puts(ok ? "No" : "Yes"); } } return 0; }
Java :
import java.util.Scanner; /** * * @author Administrator */ public class Main { public static void main(String[] args) { Scanner a=new Scanner(System.in); while(a.hasNext()){ int b=a.nextInt(); if(b==0){ return; } int y1=0,y2=0,y3=0,y4=0,u=0; String l=""; for (int i = 0; i < b; i++) { if(i==0){String gg=a.nextLine();} String g=a.nextLine(); // System.out.println(g); for (int j = 0; j <g.length(); j++) { char h=g.charAt(j); // System.out.println(h); if((h>='a'&&h<='z')||(h>='A'&&h<='Z')){ y1++; } if(h>='0'&&h<='9'){ y2++; y3++; l=l+h; } if(y1==0&&y2==0){ u++; break; } // System.out.println(y3+" "+y4); if(y3!=y4&&j!=g.length()-1){ y4=y3; }else{ if(y3>0&&ff(Integer.parseInt(l))==false){ u++; break; } l=""; y3=0;y4=0; } y1=0;y2=0; } if(u>0){ System.out.println("No"); }else{ System.out.println("Yes"); } y1=0; y2=0;y3=0;y4=0;u=0; l=""; } } } public static boolean ff(int i) { // System.out.println("ff i:"+i); for (int j = 2; j < i; j++) { if (i % j == 0) { return false; } } return true; } }
- 1
信息
- ID
- 1949
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者