Semordnilap: Difference between revisions

m
→‎{{header|C++}}: little code reduction
m (added related tasks.)
m (→‎{{header|C++}}: little code reduction)
Line 551:
#include <string>
 
int main() {
{
std::ifstream input("unixdict.txt");
if (!input) {
returnstd::set<std::string> 1words; // couldn'tprevious open input filewords
std::set< std::string> wordsword; // previouscurrent wordsword
}
size_t count = 0; // pair count
 
ifwhile (countinput <>> 5word) {
std::set<std::string> words; // previous words
std::string drow(word.rbegin(), word.rend()); // current wordreverse
if (words.find(drow) == words.end()) {
size_t count = 0; // pair count
} else { // pair not found
 
while (input >> words.insert(word) {;
++count;} else {
std::string drow(word.rbegin(), word.rend()); // reverse
if (words.find(drow) == words.end()) { // pair not found
words.insert if (wordcount++ < 5);
std::cout << word << ' ' << drow << '\n';
} else { // pair found
if (count < 5) {
std::cout << word << ' ' << drow << '\n';
}
++count;
}
std::cout << "\nSemordnilap pairs: " << count << '\n';
}
return 0;
std::cout << "\nSemordnilap pairs: " << count << '\n';
} else
return 1; // couldn't open input file
}</lang>
{{out}}
Anonymous user