1 条题解
-
0
C :
#include<stdio.h> #include<string.h> int main() { char a[1001],b[500][30],c[30]; int num[500]; int i=0,j=0,k=0,count,temp; gets(a); while(a[i]!='\0') { if(a[i]>=65&&a[i]<=90) a[i]=a[i]+32; if(a[i]==' '||a[i]==','||a[i]=='.') { b[j][k]='\0'; j++; k=0; } else { b[j][k]=a[i]; k++; } i++; } b[j][k]='\0'; count=j; for(i=0;i<=count;i++) { num[i]=1; } for(i=0;i<=count;i++) { if(b[i][0]=='\0') continue; for(j=i+1;j<=count;j++) { if(strcmp(b[i],b[j])==0) { num[i]++; b[j][0]='\0'; } } } for(i=0;i<=count;i++) { if(b[i][0]=='\0') continue; for(j=i+1;j<=count;j++) { if(strcmp(b[i],b[j])>0) { strcpy(c,b[i]); strcpy(b[i],b[j]); strcpy(b[j],c); temp=num[i]; num[i]=num[j]; num[j]=temp; } } } for(i=0;i<=count;i++) { if(b[i][0]!='\0') { j=0; while(b[i][j]!='\0') { putchar(b[i][j]); j++; } putchar(':'); printf("%d\n",num[i]); } else { i++; } } return 0; }
Java :
import java.util.Arrays; import java.util.Scanner; public class Main { private static Scanner s = new Scanner (System.in) ; public static void main(String[] args) { while(s.hasNext()){ String str = s.nextLine() ; str = str.replaceAll("\\,", "").replaceAll("\\.", "").toLowerCase() ; String strs[] = str.split("\\s+") ; Arrays.sort(strs) ; for (int i = 0; i < strs.length; i++) { int sum = 1 ; for (int j = i+1; j < strs.length; j++) { if(strs[i].equals(strs[j])){ sum++ ; strs[j]="" ; } } if(strs[i].length()>0) System.out.println(strs[i]+":"+sum); } } } }
- 1
信息
- ID
- 1471
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者