题解 | 九倍平方数
九倍平方数
https://www.nowcoder.com/practice/032c72fab5fe4a2ea8e11d40378a493d
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--)
{
string n;
cin >> n;
int sumn = 0;
int count2 = 0;
int count3 = 0;
int nlength = n.size();
bool yes = false;
for (int i = 0; i < nlength; i++)
{
if (n[i] == '2') count2++;
if (n[i] == '3') count3++;
sumn += n[i]-'0';
}
for (int i = 0; i <= count2; i++)
{
for (int j = 0; j <= count3; j++)
{
int sumntemp = sumn + i * 2 + j * 6;
if (sumntemp % 9 == 0)
{
cout << "YES" << endl;
yes = true;
}
if (yes)break;
}
if (yes)break;
}
if (!yes) cout << "NO" << endl;
}
}

查看26道真题和解析