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

Trending Topics

Online now

Members online
460
Guests online
2,193
Total visitors
2,653

Forum statistics

Threads
2,291,649
Posts
29,071,984
Members
1,211,007
Latest member
unknownyouth
Back
Top