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的更多相关文章
随机推荐
- 【ZOJ 3200】Police and Thief
ZOJ 3200 首先我写了个高斯消元,但是消出来了一些奇怪的东西,我就放弃了... 然后只好考虑dp:\(dp[i][j][k]\)表示走到了第i步,到了\((j,k)\)这个节点的概率. 那么答案 ...
- Android Studio复制项目作为一个新的工程
Android Studio复制项目作为一个新的工程 等待..... 好了 可能会安装失败 Failed to finalize session : INSTALL_FAILED_INVALID_AP ...
- 三、java三大特性--多态
面向对象编程有三大特性:封装.继承.多态. 封装隐藏了类的内部实现机制,可以在不影响使用的情况下改变类的内部结构,同时也保护了数据.对外界而已它的内部细节是隐藏的,暴露给外界的只是它的访问方法. 继承 ...
- 《Head First 设计模式》[02] 观察者模式
1.观察者模式 1.1 形象地认识观察者模式 报社的业务是出版报纸 用户像某家报社订阅了报纸,那么一旦报社有新的报纸,就会送到用户处.只要是订户,就一直会收到新报纸: 当用户不再想看报纸时,取消订阅, ...
- Spring Aop: 关于继承和execution target this @annotation
1.多态 target指通过这个对象调用的方法 (匹配标识对象的所有方法) getMethod() this指调用这个对象的方法 (匹配标识对象实现的方法) getDeclaredMethod( ...
- BodeAbp前端介绍
BodeAbp的前端可以根据自己的喜好选型,推荐React.js.angular2.js.vue.js,后续我会以react.js为例说明BodeAbp前端的一些设计思路. BodeAbp提供的前端d ...
- 实例解析forEach、for...in与for...of
在开发过程中经常需要循环遍历数组或者对象,js也为我们提供了不少方法供使用,其中就有三兄弟forEach.for...in.for...of,这三个方法应该是使用频率最高的,但很多人却一值傻傻分不清, ...
- Linux服务器更换主板后,网卡识别失败的处理方法
1)现象说明公司IDC机房里的一台线上服务器硬件报警,最后排查发现服务器主板坏了,随即联系厂商进行更换主板,最后更换后,登录服务器,发现网卡绑定及ip信息都在,但是ip却ping不通了,进一步排查,重 ...
- Heartbeat基础知识-运维小结
在日常的集群系统架构中,一般用到Heartbeat的主要就2种:1)高可用(High Availability)HA集群, 使用Heartbeat实现,也称为”双机热备”, “双机互备”, “双机”: ...
- QQ使用的使用评价
1:界面以及功能:打开软件之后探出登录窗口,基本功能的登录,找回密码,注册帐号等功能均在比较醒目的位置,界面较为友好. 将注册帐号放在打开软件的第一界面当然是正确的选择,给予用户非常直观的提示(没有帐 ...