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的更多相关文章
随机推荐
- Objective-C 锁
多线程在Objective-C项目中占有很大的比重,它能提高程序的运行效率,但也因此带来线程安全问题.而锁就是解决线程安全问题最常用的武器. 锁有很多种. 1.NSLock,非递归锁 NSLock * ...
- 完整卸载 kUbuntu-desktop from Ubuntu 14.04 LTS系统 ubuntu14.04 LTS 64Bit
sudo apt-get remove libkde3support4 k3b-data ntrack-module-libnl-0 libkrosscore4 libgpgme++2 libqapt ...
- Luogu P2700 逐个击破
qwq 同关押罪犯 对于这种希望几个对象分开的题目,只要把并查集反过来想就可以了. 既然要求删除的边权最小,那么只要反过来求给定的点不连通时保留的边权最大即为正解. 同样的,首先将边权排序,不会使敌人 ...
- fragment The specified child already has a parent. You must call removeView()
在切换Fragment的时候出现:The specified child already has a parent. You must call removeView()异常. 错误主要出在Fragm ...
- 关于PCB开窗
如果走220V,那么线宽一点,一般高电压下面不覆铜 https://blog.csdn.net/zhy295006359/article/details/77412566 假设感觉需要走大电流,那么就 ...
- IDEA注册jar包使用和常用插件
IDEA注册jar包使用 点击获取下载地址或生成注册码 一.安装完成后,先不启动,首先如下图修改相关的地方. 二.启动IDEA,并且激活IDEA IDEA插件仓库 IntelliJ IDEA Plug ...
- BZOJ4985 评分 二分答案、DP
传送门 题意:自己去看 答案满足单调性,所以考虑二分答案. 二分答案很好想,但是check并不是很好想. 考虑DP:设$f_i$表示队列中第$i$个人的分数$\geq \, mid$的代价,最开始$N ...
- C# 队列和栈 线程安全
队列是其元素以先进先出(FIFO)的方式来处理集合,先入队的元素会先读取. 栈是和队列非常类似的另一个容器,栈和队列最大的区别是后进先出(LIFO),也可以说成先进后出. 队列在现实生活中的例子数不胜 ...
- Luogu P1129 [ZJOI2007]矩阵游戏
题目意思还是比较直观的,而且这个建模的套路也很明显. 我们首先考虑从主对角线可以转移到哪些状态. 由于每一次操作都不会把同一行(列)的黑色方块分开.因此我们发现: 只要找出\(n\)个黑色棋子,让它们 ...
- [spark][python]Spark map 处理
map 就是对一个RDD的各个元素都施加处理,得到一个新的RDD 的过程 [training@localhost ~]$ cat names.txtYear,First Name,County,Sex ...