Difference between revisions of "Solução: Problema da palavra mágica (Marco Antonio)"
From AdonaiMedrado.Pro.Br
(New page: <code lang="cpp"> #include <iostream> #include <string> #include <algorithm> using namespace std; bool compare(char chara, char charb) { return (chara < charb); } int main() { string ...) |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
<code lang="cpp"> | <code lang="cpp"> | ||
| + | #include <algorithm> | ||
#include <iostream> | #include <iostream> | ||
#include <string> | #include <string> | ||
| − | |||
using namespace std; | using namespace std; | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
int main() | int main() | ||
| Line 16: | Line 11: | ||
cin >> entry; | cin >> entry; | ||
| − | if (entry.length() % 2 == 0){ | + | if (entry.length() % 2 == 0) |
| + | { | ||
word = entry.substr(0, (entry.length()/2)); | word = entry.substr(0, (entry.length()/2)); | ||
entry = entry.substr(entry.length()/2, entry.length()); | entry = entry.substr(entry.length()/2, entry.length()); | ||
| − | sort(word.begin(),word.end() | + | sort(word.begin(),word.end()); |
| − | + | ||
if (!(entry.compare(word))) | if (!(entry.compare(word))) | ||
| + | { | ||
cout << "S" << endl; | cout << "S" << endl; | ||
| − | + | return 1; | |
| − | + | } | |
} | } | ||
| − | + | cout << 'N' << endl; | |
| − | + | ||
| − | + | ||
return 0; | return 0; | ||
} | } | ||
</code> | </code> | ||
Latest revision as of 14:44, 20 May 2009
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string entry, word; cin >> entry; if (entry.length() % 2 == 0) { word = entry.substr(0, (entry.length()/2)); entry = entry.substr(entry.length()/2, entry.length()); sort(word.begin(),word.end()); if (!(entry.compare(word))) { cout << "S" << endl; return 1; } } cout << 'N' << endl; return 0; }