import java.util.*;
import java.lang.*;
import java.io.*;
class StringApp
{
// объ¤вление переменных - флаги и счетчики дл¤ всех видов слов
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 ( text.isEmpty() )
{
return;
}
// проход по символам текста загруженного в массив
for( int i = 0; i < text.length() && text.charAt(i) != 0; i++ )
{
// анализ символов: к какой группе они относ¤тс¤ и проверка состо¤ний
if ( text.charAt(i) == '*'|| text.charAt(i) == '-'|| text.charAt(i) == '+' ) // проверка принадлежности к данному типу символов
{
if ( symbolWordOngoing == 0 )
{
countLastWord();
symbolWordOngoing = 1;
}
}
else if ( Character.
isDigit( text.
charAt(i
) ) ) // проверка принадлежности к данному типу символов (цифра) {
if ( digitWordOngoing == 0 )
{
countLastWord();
digitWordOngoing = 1;
}
}
else if ( Character.
isLowerCase( text.
charAt(i
) ) ) // проверка принадлежности к данному типу символов (буква) {
if ( letterWordOngoing == 0 )
{
countLastWord();
letterWordOngoing = 1;
}
}
else
{
System.
out.
printf("error: illegal character: %c / 0x%x\n", text.
charAt(i
), text.
charAt(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
) {
StringApp app = new StringApp();
app.run();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBTdHJpbmdBcHAKeyAgIAoKICAgLy8g0L7QsdGKwqTQstC70LXQvdC40LUg0L/QtdGA0LXQvNC10L3QvdGL0YUgLSDRhNC70LDQs9C4INC4INGB0YfQtdGC0YfQuNC60Lgg0LTQu8KkINCy0YHQtdGFINCy0LjQtNC+0LIg0YHQu9C+0LIKICAgcHJpdmF0ZSBpbnQgbGV0dGVyV29yZENvdW50ID0gMDsgCiAgIHByaXZhdGUgaW50IGxldHRlcldvcmRPbmdvaW5nID0gMDsKICAgcHJpdmF0ZSBpbnQgZGlnaXRXb3JkQ291bnQgPSAwOwogICBwcml2YXRlIGludCBkaWdpdFdvcmRPbmdvaW5nID0gMDsKICAgcHJpdmF0ZSBpbnQgc3ltYm9sV29yZENvdW50ID0gMDsKICAgcHJpdmF0ZSBpbnQgc3ltYm9sV29yZE9uZ29pbmcgPSAwOwogICAKICAgLy8g0YTRg9C90LrRhtC4wqQg0LfQsNCy0LXRgNGI0LXQvdC4wqQg0YfRgtC10L3QuMKkINGB0LvQvtCy0LAg0Lgg0YPQstC10LvQuNGH0LXQvdC40LUg0YHRh9C10YLRh9C40LrQsCDRgdC70L7QstCwINC90LAg0LXQtNC40L3QuNGG0YMKICAgcHJpdmF0ZSB2b2lkIGNvdW50TGFzdFdvcmQoKQogICB7CiAgICAgIGlmICggbGV0dGVyV29yZE9uZ29pbmcgIT0gMCApIHsgbGV0dGVyV29yZE9uZ29pbmcgPSAwOyBsZXR0ZXJXb3JkQ291bnQrKzsgfQogICAgICBlbHNlIGlmICggZGlnaXRXb3JkT25nb2luZyAh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9PSAnLSd8fCB0ZXh0LmNoYXJBdChpKSA9PSAnKycgKSAvLyDQv9GA0L7QstC10YDQutCwINC/0YDQuNC90LDQtNC70LXQttC90L7RgdGC0Lgg0Log0LTQsNC90L3QvtC80YMg0YLQuNC/0YMg0YHQuNC80LLQvtC70L7QsgogICAgICAgICAgewogICAgICAgICAgICAgaWYgKCBzeW1ib2xXb3JkT25nb2luZyA9PSAwICkKICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdW50TGFzdFdvcmQoKTsKICAgICAgICAgICAgICAgIHN5bWJvbFdvcmRPbmdvaW5nID0gMTsKICAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGVsc2UgaWYgKCBDaGFyYWN0ZXIuaXNEaWdpdCggdGV4dC5jaGFyQXQoaSkgKSApIC8vINC/0YDQvtCy0LXRgNC60LAg0L/RgNC40L3QsNC00LvQtdC20L3QvtGB0YLQuCDQuiDQtNCw0L3QvdC+0LzRgyDRgtC40L/RgyDRgdC40LzQstC+0LvQvtCyICjRhtC40YTRgNCwKQogICAgICAgICAgewogICAgICAgICAgICAgaWYgKCBkaWdpdFdvcmRPbmdvaW5nID09IDAgKQogICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY291bnRMYXN0V29yZCgpOwogICAgICAgICAgICAgICAgZGlnaXRXb3JkT25nb2luZyA9IDE7CiAgICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBlbHNlIGlmICggQ2hhcmFjdGVyLmlzTG93ZXJDYXNlKCB0ZXh0LmNoYXJBdChpKSApICkgLy8g0L/RgNC+0LLQtdGA0LrQsCDQv9GA0LjQvdCw0LTQu9C10LbQvdC+0YHRgtC4INC6INC00LDQvdC90L7QvNGDINGC0LjQv9GDINGB0LjQvNCy0L7Qu9C+0LIgKNCx0YPQutCy0LApCiAgICAgICAgICB7CiAgICAgICAgICAgICBpZiAoIGxldHRlcldvcmRPbmdvaW5nID09IDAgKQogICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY291bnRMYXN0V29yZCgpOwogICAgICAgICAgICAgICAgbGV0dGVyV29yZE9uZ29pbmcgPSAxOwogICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZWxzZQogICAgICAgICAgewogICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGYoImVycm9yOiBpbGxlZ2FsIGNoYXJhY3RlcjogJWMgLyAweCV4XG4iLCB0ZXh0LmNoYXJBdChpKSwgdGV4dC5jaGFyQXQoaSkpOwogICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICB9CiAgICAgIAogICAgICBjb3VudExhc3RXb3JkKCk7IC8vINGE0LjQvdCw0LvRjNC90L7QtSDQt9Cw0LLQtdGA0YjQtdC90LjQtSDRgtC10LrRg9GJ0LXQs9C+INGB0LvQvtCy0LAKICAgICAgCiAgICAgIC8vINCy0YvQstC+0LQg0LrQvtC70LjRh9C10YHRgtCy0LAg0L/QvtGB0YfQuNGC0LDQvdC90YvRhSDRgdC70L7QsgogICAgICBTeXN0ZW0ub3V0LnByaW50ZigibGV0dGVyV29yZENvdW50ID0gJWRcbiIsIGxldHRlcldvcmRDb3VudCk7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJkaWdpdFdvcmRDb3VudCAgPSAlZFxuIiwgZGlnaXRXb3JkQ291bnQgKTsKICAgICAgU3lzdGVtLm91dC5wcmludGYoInN5bWJvbFdvcmRDb3VudCA9ICVkXG4iLCBzeW1ib2xXb3JkQ291bnQpOwogICAgICAKICAgICAgLy8g0LLRi9GH0LjRgdC70LXQvdC40LUg0LrQvtC90LXRh9C90L7Qs9C+INGA0LXQt9GD0LvRjNGC0LDRgtCwCiAgICAgIGlmKCBsZXR0ZXJXb3JkQ291bnQgPiBzeW1ib2xXb3JkQ291bnQgKSB7IFN5c3RlbS5vdXQucHJpbnRmKCLQsiDQtNCw0L3QvdC+0Lwg0YLQtdC60YHRgtC1INCx0L7Qu9GM0YjQtSDQs9GA0YPQv9C/INCx0Y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