Created
June 10, 2011 13:10
-
-
Save resure/1018801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// Максимальная длина строки | |
#define STRLEN 256 | |
using namespace std; | |
bool is_number(int ch) | |
{ | |
// Магия | |
return (ch >= 48 && ch <= 57) ? true : false; | |
} | |
bool is_letter(int ch) | |
{ | |
// Магия | |
return (ch >= 65 && ch <= 122) ? true : false; | |
} | |
int main() | |
{ | |
// Весь текст хранится в text | |
char text[100][STRLEN]; | |
// Временный буфер для строк | |
char s[STRLEN]; | |
// Общее количество строк | |
int n; | |
// Счетчик | |
int i = 0; | |
do { | |
// Читаем строку в буфер | |
gets(s); | |
// Копируем буфер в text | |
strcpy(text[++i], s); | |
// Пока пользователь не ввел пустую строку | |
} while (strlen(s) > 0); | |
// Запоминаем общее количество строк | |
n = i; | |
for (i = 0; i < n; i++) | |
{ | |
// Количество групп букв | |
int groups = 0; | |
// Флаг для обозначения групп букв | |
bool f = false; | |
for (int j = 0; j < strlen(text[i]); j++) | |
{ | |
// Начало группы букв | |
if (is_letter(text[i][j])) f = true; | |
// Проверка на конец группы букв | |
if (f == true && (!is_letter(text[i][j]) || (strlen(text[i]) - 1) == j)) | |
{ | |
groups++; | |
f = false; | |
} | |
} | |
if (groups > 1) | |
{ | |
for (int j = 0; j < strlen(text[i]); j++) | |
{ | |
// Заменяем символы на цифры | |
if (text[i][j] == '+') | |
text[i][j] = '1'; | |
if (text[i][j] == '-') | |
text[i][j] = '2'; | |
if (text[i][j] == '*') | |
text[i][j] = '3'; | |
} | |
} | |
// Вывод обработанной строки | |
cout << text[i] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment