题解
2023-06-27 16:34:33
发布于:上海
45阅读
0回复
0点赞
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int test(string s)
{
string ss = "";
int flag = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] != '0')
flag = 1;
if (flag)
ss += s[i];
}
if (flag == 0)
return 0;
for (int i = 0; i < ss.size(); i++)
if ((ss[i] != '4') and (ss[i] != '7'))
return 0;
int num = 0;
for (int i = 0; i < ss.size() / 2; i++)
num += ss[i] - '0';
int num1 = 0;
int st = ss.size() / 2;
if (ss.size() % 2 == 1)
st++;
for (int i = st; i < ss.size(); i++)
num1 += ss[i] - '0';
if (num != num1)
return 0;
return 1;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
if (test(s))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个