![]() |
|
|
Регистрация Восстановить пароль |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
![]() |
|
Опции темы | Поиск в этой теме |
![]() |
#1 |
Пользователь
Регистрация: 30.10.2011
Сообщений: 22
|
![]()
В чем суть моей проблемы: найти симметричные слова и вывести их на экран. Вроде бы с массивами строки я разобрался (функция "strtok"). помогите разобраться дальше пож-а, оч нужно.
#include "stdafx.h" #include <clocale> #include <math.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include <windows.h> #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> int _tmain(int argc, _TCHAR* argv[]) { _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); SetConsoleCP(1251); SetConsoleOutputCP(1251); int spaces = 0; FILE *fp = fopen("LabRab7.txt", "r"); if (NULL == fp) { printf("Не удалось открыть файл!\n"); return 0; } char s[1024] = ""; while (!feof(fp)) { fgets(s, 1024, fp); } char* pch; pch = strtok (s," ,.-?!"); while (pch != NULL) { printf ("%s ", pch); pch = strtok (NULL," ,.-?!"); } fclose(fp); getchar(); getchar(); return 0; } |
![]() |
![]() |
![]() |
#2 |
Пользователь
Регистрация: 30.10.2011
Сообщений: 22
|
![]()
Вот пытался что-то сделать не получилось...
for (int i = 0; i < strlen(s); i++) { if (s[i] == ' '|| s[i] == ',' || s[i] == '.' || s[i] == '-' || s[i] == '?' || s[i] == '!') { spaces++; } } for (int j = 0; j < spaces; j++) { for(int k = spaces; k <= spaces/2; k--) { if (pch[j] == pch[k]) { printf("Существуют симметричные слова!\n"); } } } |
![]() |
![]() |