注意:我写的这个问题仅适用于了解ACM问题的人。
我对这个问题有疑问。我为此写了一个很好的解决方案,但每次发送都会得到错误的答案。我不知道这里有什么问题。我测试了很多测试用例的代码。你能帮我修改一下我的代码吗?
以下是问题的链接:http://sharecode.ir/section/problemset/problem/2551
。
这是我的代码:
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
map <char, int> word2; word2['P'] = 1; word2['W'] = 1;
word2['A'] = 1; word2['D'] = 1; word2['G'] = 1; word2['J'] = 1; word2['m'] = 1; word2['Q'] = 2; word2['T'] = 1; word2['X'] = 2;
word2['B'] = 2; word2['E'] = 2; word2['H'] = 2; word2['K'] = 2; word2['N'] = 2; word2['R'] = 3; word2['U'] = 2; word2['Y'] = 3;
word2['C'] = 3; word2['F'] = 3; word2['I'] = 3; word2['L'] = 3; word2['O'] = 3; word2['S'] = 4; word2['V'] = 3; word2['Z'] = 4;
string word3, word4;
while (n--)
{
cin >> word3 >> word4;
int cntr = 0, cntr2 = 0;
for (int i = 0; i < word3.size(); i++)
cntr += word2[word3[i]];
for (int i = 0; i < word4.size(); i++)
cntr2 += word2[word4[i]];
if (cntr2 == cntr)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
答案 0 :(得分:2)
您在地图中的索引全部大写,但以下情况除外:
word2['m'] // Lowercase.
这是你的问题。
答案 1 :(得分:1)
我找到了我写的“我”的答案,但它应该是'M'我修复它。