-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from AlgoLeadMe/16-YIM2UL2ET
16-YIM2UL2ET
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
bool isOneChar(std::string str) { | ||
int size = str.size(); | ||
for (int i = 1; i < size; i++) { | ||
if (str[i-1] != str[i]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
int main(void) { | ||
std::string str, rstr; | ||
std::cin >> str, rstr = str; | ||
std::reverse(rstr.begin(), rstr.end()); | ||
|
||
if (isOneChar(str)) std::cout << -1; | ||
else if (str == rstr) std::cout << str.size()-1; | ||
else std::cout << str.size(); | ||
|
||
return 0; | ||
} |