🔒 Closed C++ string palindrome problem

Status
Not open for further replies.
Patulong naman po sa mga nakakaalam ng C++, here's the problem:
Input sentence string then separate each word. Determine the palindromes and tell how many times they appear in the string.

EXAMPLE:
----
INPUT: asd qwerty aaa sdfgah sas sas
OUTPUT:
aaa — 1
sas — 2
----
 
InfiniteTsukiyomi

1) Pwede mo munang i-split yung string using delimiter.
Complete Example:
Code:
std::string s = "scott>=tiger>=mushroom";
std::string delimiter = ">=";

size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout << token << std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;
Output:
Code:
scott
tiger
mushroom
Link: You do not have permission to view the full content of this post. Log in or register now.

2) Kapag nakuha mo yung 'token' dun sa loob ng 'while loop', pwede mong gamitin ang 'find' function ng std::string para mabiling yung 'token' sa loob ng string
 
InfiniteTsukiyomi

1) Pwede mo munang i-split yung string using delimiter.
Complete Example:
Code:
std::string s = "scott>=tiger>=mushroom";
std::string delimiter = ">=";

size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout << token << std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;
Output:
Code:
scott
tiger
mushroom
Link: You do not have permission to view the full content of this post. Log in or register now.

2) Kapag nakuha mo yung 'token' dun sa loob ng 'while loop', pwede mong gamitin ang 'find' function ng std::string para mabiling yung 'token' sa loob ng string

thaaanks po. strtok nalang ata hehe
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 782
    Views
  • 3
    Participants
Last reply from:
InfiniteTsukuyomi

Trending Topics

Online now

Members online
429
Guests online
7,725
Total visitors
8,154

Forum statistics

Threads
2,338,659
Posts
29,304,811
Members
1,124,504
Latest member
Johncena0301
Back
Top