codeforces146A
Lucky Ticket
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky.
Input
The first line contains an even integer n (2 ≤ n ≤ 50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n — the ticket number. The number may contain leading zeros.
Output
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
Examples
2
47
NO
4
4738
NO
4
4774
YES
Note
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number.
sol:按题意暴力模拟就可以了
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,A[N];
int main()
{
int i,S1=,S2=;
R(n);
for(i=;i<=n;i++)
{
char ch=' ';
while(!isdigit(ch)) ch=getchar();
A[i]=ch-'';
if((A[i]!=)&&(A[i]!=)) return *puts("NO");
if(i<=(n>>)) S1+=A[i]; else S2+=A[i];
}
if(S1!=S2) puts("NO");
else puts("YES");
return ;
}
/*
input
6
477477
output
YES
*/
codeforces146A的更多相关文章
随机推荐
- jenkins安装Scanner插件
环境centos7 第一步安装scaner插件 第二步 重启之后配置sonarqube 进入Jenkins-->系统管理-->系统设置,找到sonarqube servers,填写相关信息 ...
- Python常见十六个错误集合,你知道那些?
使用python会出现各种各样的错误,以下是Python常见的错误以及解决方法. 1.ValueError: 'Conv2d_1a_3×3' is not a valid scope name 这个是 ...
- security相关链接整理
token令牌 ssl协议 https协议 对称加密与非对称加密 认识ASP.NET Windows身份认证
- IIS导入.pfx证书时报错:"A specified logon session does not exist. It may already have been terminated."
在IIS中可以直接导入.pfx文件来给站点绑定https协议: 如果在导入.pfx文件时,不选择"Allow this certificate to be exported"的话 ...
- 实现Repeater控件的记录单选
有朋友问及,在Repeater控件中第一列放置一个RadioButton,实现对记录的单选. 下面Insus.NET想举个例子来实现与说明. 为Repeater控件准备数据: 在ASPX网页上,写好R ...
- Newtonsoft的序列化和反序列化
class test { public string a; public int b; public byte[] c; public In ...
- Error【0007】:zabbix中因为curl版本过低而无法发送邮件
1. 错误背景 在centos6.5上,源码部署zabbix最新版本zabbix-3.2.14.部署后之后,在配置邮件发送报警时出错 2. 错误提示 3. 原因分析 从网上检索的结果是说,系统中的cu ...
- Ionic 3 延迟加载(Lazy Load)实战(一)
本文分享并演示了在 Ionic 3 框架中如何进行模块的延迟加载(Lazy Load)开发. 在我的实战课程「快速上手Ionic3 多平台开发企业级问答社区」中,因为开发的仿知乎 App 模块间的加载 ...
- Steamworks上传游戏
1.在steamPipe下配置Depot,每个Depot表示程序对应的分支配置语言,操作系统,架构组合等 2.安装,启动项目是配置游戏启动文件的相关信息,不同的操作系统架构等需要添加不同的启动项 3. ...
- 使用github的感想
github的仓库链接:https://github.com/liyan941016/test github是一个基于git的代码托管平台,要想使用github第一步就要注册账户,然后要创建一个仓库 ...