码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank - Game of Thrones - I

时间:2015-02-27 07:43:23      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

HackerRank - Game of Thrones - I

标签:

原文地址:http://www.cnblogs.com/tonix/p/4302504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!