import java.io.*;
import java.util.Arrays;
import java.util.IllegalFormatException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class Main{
public static void main(String[] args) throws FileNotFoundException {
TextIO.readStream(System.in);
int n=TextIO.getlnInt();
String m[]=new String[n];
String fin[]=new String[n];
int finN[]=new int[n];
for(int i=0;i<n;i++){
m[i]=TextIO.getlnString().split(" ")[0];
fin[i]="";
}
Arrays.sort(m);
for(int i=0,counter=0;i<n;i++){
if(fin[counter].equals(m[i])){
finN[counter]++;
}else{
counter++;
fin[counter]=m[i];
finN[counter]=1;
}
}
for(int i=0;i<n;i++){
if(!fin[i].equals(""))
System.out.println(fin[i]+" "+finN[i]);
}
}
}
import java.util.Arrays;
import java.util.IllegalFormatException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class Main{
public static void main(String[] args) throws FileNotFoundException {
TextIO.readStream(System.in);
int n=TextIO.getlnInt();
String m[]=new String[n];
String fin[]=new String[n];
int finN[]=new int[n];
for(int i=0;i<n;i++){
m[i]=TextIO.getlnString().split(" ")[0];
fin[i]="";
}
Arrays.sort(m);
for(int i=0,counter=0;i<n;i++){
if(fin[counter].equals(m[i])){
finN[counter]++;
}else{
counter++;
fin[counter]=m[i];
finN[counter]=1;
}
}
for(int i=0;i<n;i++){
if(!fin[i].equals(""))
System.out.println(fin[i]+" "+finN[i]);
}
}
}
No comments:
Post a Comment