什么是产生字谜的最佳策略.
Run Code Online (Sandbox Code Playgroud)An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; ex.
- 十一加二是十二加一的字谜
- 小数点是我是一个圆点的字谜
- 天文学家是月球凝视者的字谜
起初它看起来很简单,只是混杂字母并生成所有可能的组合.但是,只生成字典中的单词的有效方法是什么呢?
我遇到了这个页面,在Ruby中解决了字谜.
但你有什么想法?
你如何列出彼此字谜的单词?
当我申请当前的工作时,我被问到了这个问题.
orchestra可以将carthorse所有原始字母重新排列成一次,因此这些单词是彼此的字谜.
给定两个字符串A和B,检查它们是否是字谜.
如果通过重新排列另一个字母可以获得一个字符串,则称两个字符串为字谜.
字谜的例子是
dog, god abac, baac123, 312abab, aaba而dab, baad不是字谜.
输入:
输入的第一行是测试用例T的数量.接着是T行,每行有两个空格分隔的字符串A和B;
OUTPUT
对于每个测试用例,如果是anagrams则打印"YES",否则打印"NO".(不含引号)
约束
`
Sample Input Sample Output
------------------------------------
3 YES
abcd bcda NO
bad daa YES
a1b2c3 abc123 NO
Run Code Online (Sandbox Code Playgroud)
我们应该怎么做 ?
bool anagramChecker(string first, string second)
{
if(first.Length != second.Length)
return false;
if(first == second)
return true;//or false: Don't know whether a string counts as an anagram of itself
Dictionary<char, int> pool = …Run Code Online (Sandbox Code Playgroud)