#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
while (m--)
{
string s;
cin >> s;
for (auto &c : s)
{
if (c == 'y') c = '1';
else c = '0';
}
bitset<30> b(s);
cout << (int)pow(2, n) - b.to_ulong() << endl;
}
return 0;
}
或者
#include <bits/stdc++.h>
using namespace std;
int base10(string s) // 秦九韶算法
{
int sum = 0;
for (auto c : s)
sum = sum * 2 + c - '0';
return sum;
}
int main()
{
int n, m;
cin >> n >> m;
while (m--)
{
string s;
cin >> s;
for (auto &c : s)
{
if (c == 'y') c = '1';
else c = '0';
}
cout << (int)pow(2, n) - base10(s) << endl;
}
return 0;
}