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; }
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
- 874
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者