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; }
Pascal :
var a,b:string; i:integer; s:real; begin while not eof do begin readln(a);b:=copy(a,1,1);s:=0; delete(a,1,2);a:=upcase(a);b:=upcase(b); for i:=1 to length(a) do if a[i]=b then s:=s+1; writeln(s/length(a):0:5); end; end.
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()); } } }
Python :
import sys for line in sys.stdin: data = line.split() a = data[0].lower() b = data[1].lower() c = b.count(a) d = len(data[1]) print '%0.5f'%(float(c)/d)
C# :
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string str; while ((str=Console.ReadLine())!=null) { str = str.ToLower(); string[] ans = str.Split(' '); char ch=ans[0][0]; int num = ans[1].Split(ch).Length-1; double result = num * 1.0 / ans[1].Length; Console.WriteLine(result.ToString("f5")); } } } }
- 1
信息
- ID
- 6234
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者