字符串统计
来源:互联网 发布:wifi连不上网络 有信号 编辑:程序博客网 时间:2024/06/05 03:41
输出m个字符串,要求输出重复n次的字符串有几个
import java.util.Arrays;import java.util.Scanner;public class countReStr { public static void main(String[] args) { // TODO Auto-generated method stub int j; int m; Scanner in = new Scanner(System.in); int n = in.nextInt(); String[] Str = new String[n]; int[] count = new int[n]; // int[] count2=new int[n]; in.nextLine(); for (int i = 0; i < n; i++) { Str[i] = in.nextLine(); } Arrays.sort(Str); for (int i = 0; i < n; i++) { count[i] = 1; } for (int i = 0; i < n;) { for (j = i + 1; j < n; j++) { if (Str[i].equals(Str[j])) { count[i]++; count[j]=count[i]; } else continue; } i = i + j - 1; } Arrays.sort(count); int count2=1; for(int i=0;i<n;){ for( m=i+1;m<n;m++){ if(count[i]==count[m]){ count2++; }else{ continue; } }System.out.println(count[i]+" "+count2); i = i + m-1 ; count2=1; } }}
import java.util.Arrays;import java.util.Scanner;/* * 统计出字符串数组中重复出现的字符串的个数 */public class countReStr { public static void main(String[] args) { // TODO Auto-generated method stub int j; int m; Scanner in = new Scanner(System.in); int n = in.nextInt(); String[] Str = new String[n]; int[] count = new int[n]; in.nextLine(); for (int i = 0; i < n; i++) { Str[i] = in.nextLine(); } Arrays.sort(Str); for (int i = 0; i < n; i++) { count[i] = 1; } System.out.println(); for(int i=0;i<n;){ for(j=i+1;j<n;j++){ if(Str[i].equals(Str[j])){ count[i]++; for(int k=i;k<=j;k++){ count[k]=count[i]; } }else break; } i=j; } Arrays.sort(count); int count2=1; for(int i=0;i<n;){ for( m=i+1;m<n;m++){ if(count[i]==count[m]){ count2++; }else break; }System.out.println(count[i]+" "+count2); count2=1; i=m; } }}
0 0
- 统计字符串
- 统计字符串
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- 统计字符串
- 字符串统计
- 字符串统计
- 字符串统计
- 字符串统计
- JAVA设计模式之工厂模式(简单工厂模式+工厂方法模式)
- static的用法
- html下拉菜单
- java 读取 dbf数据库的dbf文件代码
- Linked list cycle [leetcode]
- 字符串统计
- Vuex 模块化实现待办事项的状态管理
- Oracle笔记--row_number rank dense_rank
- 腾讯云服务器搭建SVN
- 《图解HTTP[上野宣]》读书笔记一
- HDU 1847 Good Luck in CET-4 Everybody! (SG函数)
- 优化查询sql
- 利用PL/SQL创建Oracl外部表
- 关于EXCEL操作