import java.util.*;
import java.lang.*;
import java.io.*;
class CharArrApp
{
// объ¤вление переменных - флаги и счетчики дл¤ всех видов слов
private int letterWordCount = 0;
private int letterWordOngoing = 0;
private int digitWordCount = 0;
private int digitWordOngoing = 0;
private int symbolWordCount = 0;
private int symbolWordOngoing = 0;
// функци¤ завершени¤ чтени¤ слова и увеличение счетчика слова на единицу
private void countLastWord()
{
if ( letterWordOngoing != 0 ) { letterWordOngoing = 0; letterWordCount++; }
else if ( digitWordOngoing != 0 ) { digitWordOngoing = 0; digitWordCount++; }
else if ( symbolWordOngoing != 0 ) { symbolWordOngoing = 0; symbolWordCount++; }
}
public void run()
{
// загрузка текста в массив - цикл считывани¤ одного символа текста
Scanner in
= new Scanner
(System.
in); in.close();
if ( s.isEmpty() )
{
return;
}
char[] text = s.toCharArray();
// проход по символам текста загруженного в массив
for( int i = 0; i < text.length && text[i] != 0; i++ )
{
// анализ символов: к какой группе они относ¤тс¤ и проверка состо¤ний
if ( text[i] == '*'|| text[i] == '-'|| text[i] == '+' ) // проверка принадлежности к данному типу символов
{
if ( symbolWordOngoing == 0 )
{
countLastWord();
symbolWordOngoing = 1;
}
}
else if ( Character.
isDigit( text
[i
] ) ) // проверка принадлежности к данному типу символов (цифра) {
if ( digitWordOngoing == 0 )
{
countLastWord();
digitWordOngoing = 1;
}
}
else if ( Character.
isLowerCase( text
[i
] ) ) // проверка принадлежности к данному типу символов (буква) {
if ( letterWordOngoing == 0 )
{
countLastWord();
letterWordOngoing = 1;
}
}
else
{
System.
out.
printf("error: illegal character: %c / 0x%x\n", text
[i
], text
[i
]); return;
}
}
countLastWord(); // финальное завершение текущего слова
// вывод количества посчитанных слов
System.
out.
printf("letterWordCount = %d\n", letterWordCount
); System.
out.
printf("digitWordCount = %d\n", digitWordCount
); System.
out.
printf("symbolWordCount = %d\n", symbolWordCount
);
// вычисление конечного результата
if( letterWordCount
> symbolWordCount
) { System.
out.
printf("в данном тексте больше групп букв, чем групп знаков\n"); } else if ( letterWordCount
== symbolWordCount
) { System.
out.
printf("в данном тексте одинаковое количество групп букв и групп знаков\n"); } else { System.
out.
printf("в данном тексте групп букв меньше, чем групп знаков\n"); } }
public static void main
( String[] args
) {
CharArrApp app = new CharArrApp();
app.run();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBDaGFyQXJyQXBwCnsgICAKCiAgIC8vINC+0LHRisKk0LLQu9C10L3QuNC1INC/0LXRgNC10LzQtdC90L3Ri9GFIC0g0YTQu9Cw0LPQuCDQuCDRgdGH0LXRgtGH0LjQutC4INC00LvCpCDQstGB0LXRhSDQstC40LTQvtCyINGB0LvQvtCyCiAgIHByaXZhdGUgaW50IGxldHRlcldvcmRDb3VudCA9IDA7IAogICBwcml2YXRlIGludCBsZXR0ZXJXb3JkT25nb2luZyA9IDA7CiAgIHByaXZhdGUgaW50IGRpZ2l0V29yZENvdW50ID0gMDsKICAgcHJpdmF0ZSBpbnQgZGlnaXRXb3JkT25nb2luZyA9IDA7CiAgIHByaXZhdGUgaW50IHN5bWJvbFdvcmRDb3VudCA9IDA7CiAgIHByaXZhdGUgaW50IHN5bWJvbFdvcmRPbmdvaW5nID0gMDsKICAgCiAgIC8vINGE0YPQvdC60YbQuMKkINC30LDQstC10YDRiNC10L3QuMKkINGH0YLQtdC90LjCpCDRgdC70L7QstCwINC4INGD0LLQtdC70LjRh9C10L3QuNC1INGB0YfQtdGC0YfQuNC60LAg0YHQu9C+0LLQsCDQvdCwINC10LTQuNC90LjRhtGDCiAgIHByaXZhdGUgdm9pZCBjb3VudExhc3RXb3JkKCkKICAgewogICAgICBpZiAoIGxldHRlcldvcmRPbmdvaW5nICE9IDAgKSB7IGxldHRlcldvcmRPbmdvaW5nID0gMDsgbGV0dGVyV29yZENvdW50Kys7IH0KICAgICAgZWxzZSBpZiAoIGRpZ2l0V29yZE9uZ29pbmcgIT0gMCApIHsgZGlnaXRXb3JkT25nb2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fHwgdGV4dFtpXSA9PSAnKycgKSAvLyDQv9GA0L7QstC10YDQutCwINC/0YDQuNC90LDQtNC70LXQttC90L7RgdGC0Lgg0Log0LTQsNC90L3QvtC80YMg0YLQuNC/0YMg0YHQuNC80LLQvtC70L7QsgogICAgICAgICAgewogICAgICAgICAgICAgaWYgKCBzeW1ib2xXb3JkT25nb2luZyA9PSAwICkKICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdW50TGFzdFdvcmQoKTsKICAgICAgICAgICAgICAgIHN5bWJvbFdvcmRPbmdvaW5nID0gMTsKICAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGVsc2UgaWYgKCBDaGFyYWN0ZXIuaXNEaWdpdCggdGV4dFtpXSApICkgLy8g0L/RgNC+0LLQtdGA0LrQsCDQv9GA0LjQvdCw0LTQu9C10LbQvdC+0YHRgtC4INC6INC00LDQvdC90L7QvNGDINGC0LjQv9GDINGB0LjQvNCy0L7Qu9C+0LIgKNGG0LjRhNGA0LApCiAgICAgICAgICB7CiAgICAgICAgICAgICBpZiAoIGRpZ2l0V29yZE9uZ29pbmcgPT0gMCApCiAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjb3VudExhc3RXb3JkKCk7CiAgICAgICAgICAgICAgICBkaWdpdFdvcmRPbmdvaW5nID0gMTsKICAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGVsc2UgaWYgKCBDaGFyYWN0ZXIuaXNMb3dlckNhc2UoIHRleHRbaV0gKSApIC8vINC/0YDQvtCy0LXRgNC60LAg0L/RgNC40L3QsNC00LvQtdC20L3QvtGB0YLQuCDQuiDQtNCw0L3QvdC+0LzRgyDRgtC40L/RgyDRgdC40LzQstC+0LvQvtCyICjQsdGD0LrQstCwKQogICAgICAgICAgewogICAgICAgICAgICAgaWYgKCBsZXR0ZXJXb3JkT25nb2luZyA9PSAwICkKICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdW50TGFzdFdvcmQoKTsKICAgICAgICAgICAgICAgIGxldHRlcldvcmRPbmdvaW5nID0gMTsKICAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGVsc2UKICAgICAgICAgIHsKICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJlcnJvcjogaWxsZWdhbCBjaGFyYWN0ZXI6ICVjIC8gMHgleFxuIiwgdGV4dFtpXSwgdGV4dFtpXSk7CiAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgIH0KICAgICAgCiAgICAgIGNvdW50TGFzdFdvcmQoKTsgLy8g0YTQuNC90LDQu9GM0L3QvtC1INC30LDQstC10YDRiNC10L3QuNC1INGC0LXQutGD0YnQtdCz0L4g0YHQu9C+0LLQsAogICAgICAKICAgICAgLy8g0LLRi9Cy0L7QtCDQutC+0LvQuNGH0LXRgdGC0LLQsCDQv9C+0YHRh9C40YLQsNC90L3Ri9GFINGB0LvQvtCyCiAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJsZXR0ZXJXb3JkQ291bnQgPSAlZFxuIiwgbGV0dGVyV29yZENvdW50KTsKICAgICAgU3lzdGVtLm91dC5wcmludGYoImRpZ2l0V29yZENvdW50ICA9ICVkXG4iLCBkaWdpdFdvcmRDb3VudCApOwogICAgICBTeXN0ZW0ub3V0LnByaW50Zigic3ltYm9sV29yZENvdW50ID0gJWRcbiIsIHN5bWJvbFdvcmRDb3VudCk7CiAgICAgIAogICAgICAvLyDQstGL0YfQuNGB0LvQtdC90LjQtSDQutC+0L3QtdGH0L3QvtCz0L4g0YDQtdC30YPQu9GM0YLQsNGC0LAKICAgICAgaWYoIGxldHRlcldvcmRDb3VudCA+IHN5bWJvbFdvcmRDb3VudCApIHsgU3lzdGVtLm91dC5wcmludGYoItCyINC00LDQvdC90L7QvCDRgtC10LrRgdGC0LUg0LHQvtC70YzRiNC1INCz0YDRg9C/0L8g0LHRg9C60LIsINGH0LXQvCDQs9GA0YPQv9C/INC30L3QsNC60L7Q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