UVA Solution 353 - Pesky Palindromes - Solution in C, C++ | Volume 3
UVA Online Judge Solution 353 - Pesky Palindromes | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=289
Problem Name: 353 - Pesky Palindromes
Problem Number : UVA - 353 - Pesky Palindromes
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus
UVA Solution 353 - Pesky Palindromes Code in C, CPP:
#include <iostream> #include <string.h> #include <set> using namespace std; int main() { string s; while(cin >> s) { set<string> p; int i, len = s.length(), l, r; for(i = 0; i < len; i++) { l = i, r = i; while(l >= 0 && r < len && s[l] == s[r]) { p.insert(s.substr(l, r-l+1)); l--, r++; } if(i != len-1 && s[i] == s[i+1]) { l = i, r = i+1; while(l >= 0 && r < len && s[l] == s[r]) { p.insert(s.substr(l, r-l+1)); l--, r++; } } } cout << "The string '" << s << "' contains " << p.size() << " palindromes."<< endl; } return 0; }
No comments:
Post a Comment