1 条题解
-
0
C :
#include<stdio.h> #include<string.h> #include<ctype.h> int main() { int i,n; char c,a[201]; while(scanf("%c%*c%s%*c",&c,a)!=EOF) { for(n=i=0;i<strlen(a);i++) if(c==tolower(a[i])||c==toupper(a[i])) n++; printf("%.5f\n",n*1.0/strlen(a)); } return 0; }
C++ :
#include<stdio.h> #include<string.h> #include<ctype.h> int main() { int i,n; char c,a[201]; while(scanf("%c%*c%s%*c",&c,a)!=EOF) { for(n=i=0;i<strlen(a);i++) if(c==tolower(a[i])||c==toupper(a[i])) n++; printf("%.5f\n",n*1.0/strlen(a)); } return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ char c = in.next().charAt(0); if(c<='Z')c = (char) (c-'A'+'a'); String s = in.next(); int cou = 0; for(int i=0;i<s.length();i++){ char tem = s.charAt(i); if(tem<='Z')tem = (char) (tem-'A'+'a'); if(tem==c)cou++; } System.out.printf("%.5f\n", (float)cou/(float)s.length()); } } }
- 1
信息
- ID
- 1449
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者