您的位置:首页 > 其它

HackerRank - Game of Thrones - I

2015-02-27 07:05 218 查看
You may also have seen this problem in interview questions. Two cases:

1. all chars have even numbers of it
2. only 1 char have odd numbers of it

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {

string s;
cin>>s;

int flag = 0;
// Assign Flag a value of 0 or 1 depending on whether or not you find what you are looking for, in the given string

int rec[26] = {0};
for(auto c : s)    rec[c - 'a'] ++;

int oddCnt = 0;
for(int i = 0; i < 26; i ++)
oddCnt += rec[i] % 2 ? 1 : 0;
flag = oddCnt <= 1 ? 1 : 0;

if(flag==0)     cout<<"NO";
else            cout<<"YES";
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: