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

Trending Topics

Online now

Members online
1,131
Guests online
3,546
Total visitors
4,677

Forum statistics

Threads
2,278,274
Posts
28,982,094
Members
1,228,296
Latest member
cabasag
Back
Top