🔒 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
  • 779
    Views
  • 3
    Participants
Last reply from:
InfiniteTsukuyomi

Trending Topics

Online now

Members online
1,049
Guests online
3,167
Total visitors
4,216

Forum statistics

Threads
2,328,726
Posts
29,244,153
Members
1,158,020
Latest member
zehjilon12
Back
Top