題目連結: https://zerojudge.tw/ShowProblem?problemid=a224
# 解題思路
計算數量吧!!
如果最多只有一組不是偶數 (成對),就一定能夠回文
(記得轉換一下大小寫)
# 程式碼
#include <iostream> | |
using namespace std; | |
int main() { | |
string s; | |
while ( cin >> s ) { | |
int appear[256] = {0}, oddCnt = 0; | |
for ( int i = 0; i < s.length(); i++ ) | |
if ( isalpha ( s[i] ) ) { | |
s[i] = toupper ( s[i] ); | |
appear[s[i]]++; | |
} | |
for ( int i = 0; i < 256; i++ ) | |
if ( appear[i] % 2 !=0 ) | |
oddCnt++; | |
if(oddCnt<=1)// 中間那一個可能只出現一次 | |
cout<<"yes !"<<endl; | |
else | |
cout<<"no..."<<endl; | |
} | |
return 0; | |
} |