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
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
- 【HackerRank】 Game Of Thrones - I
- 【HackerRank】Game Of Rotation
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (序)
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (11-12)
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (23-24)
- [美剧赏析] 权力的游戏<Game of Thrones> 前六季总结
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (7-8)
- daily_journal_3 the game of thrones
- Hackerrank Week of Code 32
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (51-52)
- HackerRank - organizing-containers-of-balls
- hackerrank_Permutation game
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (1-2)
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (13-14)
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (25-26)
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (41-42)
- HackerRank Week of Code 26
- [HackerRank 101 Hack 51] Testing the Game
- HackerRank: Bricks Game