1 条题解
-
0
C :
#include <stdio.h> #include <stdlib.h> #include "string.h" int main() { char temp; int i , arry[10] = {0}; while((temp = getchar()) != '.') { arry[temp - 48]++; } for(i = 0;i < 10; i ++) { if(arry[i] != 0) { printf("%d:%d",i,arry[i]); printf(" "); } } return 0; }
C++ :
//#include "stdafx.h" #include <iostream> #include <cstring> using namespace std; int main() { int i,j; int num[10] = {0}; char temp; while((temp = getchar())!='.') { num[temp-48]++; } for(i=0;i<10;i++) if(num[i]!=0){ cout<<i<<":"<<num[i]<<" "; } cout<<endl; return 0; }
Pascal :
var s:string;k:char; i:longint; f:array[0..10] of longint; begin readln(s); for i:=1 to length(s) do if s[i] in ['0'..'9'] then inc(f[ord(s[i])-48]); for i:=0 to 9 do if f[i] <>0 then write(i,':',f[i],' ') end.
Java :
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); input.useDelimiter("\\.");//英文句号 StringBuffer str=new StringBuffer(input.next()); int[] a=new int[str.length()]; for(int i=0;i<str.length();i++) { a[i]=Integer.parseInt(String.valueOf(str.charAt(i))); } int count=0; int[] c=new int[10]; for(int i=0;i<10;i++) { for(int j=0;j<str.length();j++) { if(a[j]==i) { count++; } } c[i]+=count; count=0; } for(int i=0;i<10;i++) { if(c[i]!=0) { System.out.print(i+":"+c[i]+" "); } } } }
- 1
信息
- ID
- 1259
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者