What's new

Closed C++ string palindrome problem

Status
Not open for further replies.
Joined
Jan 29, 2017
Posts
173
Reaction
32
Points
106
Age
25
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.

Similar threads

Back
Top