-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_lab5_a.java
72 lines (64 loc) · 1.62 KB
/
string_lab5_a.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.Scanner;
public class string_lab5_a {
public static void main(String[] args) {try{
Scanner sin=new Scanner(System.in);
String str,str_all="";
System.out.println("Ââåäèòå ñâîé òåêñò.\nÄëÿ âûõîäà èç ñîñòîÿíèÿ ââîäà íàáåðèòå exit\n");
str=sin.nextLine();
while(str.compareToIgnoreCase("exit")!=0)
{
str_all+=str;
str=sin.nextLine();
}
if(!str_all.isEmpty()){
str_all=str_all.replace(".", " ");
str_all=str_all.replace(","," ");
str_all=str_all.replace("!"," ");
str_all=str_all.replace("?"," ");
str_all=str_all.toLowerCase();
String str_mas[]= str_all.split(" ");
String vowel_mas[]={"à","î","ó","þ","ÿ","ý","è","û","å","¸"};
double ratio_mas[]=new double[str_mas.length];
for(int i=0;i<str_mas.length;i++)
{
double vowel=0;
if(!str_mas[i].equals("")){
str_mas[i]+=" ";
for(int k=0;k<10;k++)
vowel += str_mas[i].split(vowel_mas[k]).length - 1;
str_mas[i]=str_mas[i].trim();
ratio_mas[i]= vowel/str_mas[i].length();
}
else
ratio_mas[i]=0;
}
for(int i=0;i<str_mas.length-1;i++)
{
for(int j=i+1;j<str_mas.length;j++)
{
if(ratio_mas[i]>ratio_mas[j])
{
String t = str_mas[i];
str_mas[i]=str_mas[j];
str_mas[j]=t;
double t_d=ratio_mas[i];
ratio_mas[i]=ratio_mas[j];
ratio_mas[j]=t_d;
}
}
}
System.out.println("\nÓïîðÿäî÷åííûå ñëîâà:");
for(int i=0;i<str_mas.length;i++)
if(!str_mas[i].equals(""))
System.out.println("\t"+str_mas[i]);
}
else
System.out.println("\nÂû íå ââåëè ñëîâà");
sin.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}