Циклами как-то неинтересно. string намного проще, но все же функции cstring никто не отменял
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| #include <iostream>
#include <cstring>
int main()
{
const char* p = "this;isi;now;aba!";
const char* delim = ";";
const size_t p_len = strlen(p);
char* without_pling = new char[p_len + 1];
strncpy(without_pling, p, p_len - 1);
for (char* c = strtok(without_pling, delim); c; c = strtok(0, delim))
{
const size_t size = strlen(c);
if (size && c[0] == c[size - 1])
{
std::cout << c << std::endl;
}
}
delete[] without_pling;
} |
|
http://liveworkspace.org/code/29f5c818e0baffa61ff603e8aa7d6592