Lucky Ticket

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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).

Sample Input

Input
2
47
Output
NO
Input
4
4738
Output
NO
Input
4
4774
Output
YES

Hint

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.

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
char a[];
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
int flg=,s1=,s2=;
scanf("%s",a);
for(i=;i<n;i++)
{
if(i<n/)
s1=s1+a[i]-'';
else
s2=s2+a[i]-'';
if(a[i]=='' || a[i]=='')
{
flg=;
}
else
{
flg=;
break;
}
}
//printf("%d %d\n",s1,s2);
if(s1!=s2)
flg=;
if(flg)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

CodeForces 146A Lucky Ticket的更多相关文章

  1. Codeforces 121A Lucky Sum

    Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  2. codeforces 630C Lucky Numbers

    C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...

  3. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  4. CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元

    题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...

  5. codeforces 630C - Lucky Numbers 递推思路

    630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦 ...

  6. Codeforces 145E Lucky Queries 线段树

    Lucky Queries 感觉是很简单的区间合并, 但是好像我写的比较麻烦. #include<bits/stdc++.h> #define LL long long #define f ...

  7. CodeForces 146E Lucky Subsequence(组合数+DP)

    题目描述 Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers w ...

  8. CodeForces 122G Lucky Array(一脸懵逼的树状数组)

    Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal re ...

  9. codeforces 110E Lucky Tree

    传送门:https://codeforces.com/contest/110/problem/E 题意:给你一颗树,节点与节点之间的边有一个边权,定义只由4和7组成的数字是幸运数字,现在要你求一共有多 ...

随机推荐

  1. archlinux安装输入法需要的包及archlinux无法使用输入法的解决

    所需的包: fcitx #这货应该是主要的程序 fcitx-configtool #图形化的配置工具,非必须 fcitx-gtk2 fcitx-gtk3 fcitx-qt4 fcitx-qt5 fci ...

  2. [sinatra] Just Do It: Learn Sinatra, Part One Darren Jones

    1. Install sinatra gem gem install sinatra --no-ri --no-rdoc 2. Basic App #!/usr/bin/ruby require 's ...

  3. /etc/passwd /etc/shadow

    一./etc/passwd/etc/passwd 文件是一个纯文本文件,每行采用了相同的格式: name:password:uid:gid:comment:home:shell name 用户登录名  ...

  4. pycharm常用快捷键

    Alt+Enter 自动添加包Ctrl+t SVN更新Ctrl+k SVN提交Ctrl + / 注释(取消注释)选择的行Ctrl+Shift+F 高级查找Ctrl+Enter 补全Shift + En ...

  5. linux驱动的入口函数module_init的加载和释放【转】

    本文转载自:http://blog.csdn.net/zhandoushi1982/article/details/4927579 就像你写C程序需要包含C库的头文件那样,Linux内核编程也需要包含 ...

  6. laravel数据库的创建和迁移

    数据库建立及迁移 Laravel 5 把数据库配置的地方改到了 `learnlaravel5/.env`,打开这个文件,编辑下面四项,修改为正确的信息: ? 1 2 3 4 5 6 7 DB_HOST ...

  7. C# ZipHelper C#公共类 压缩和解压

    关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 1.基本介绍 由于项目中需要用到各种压缩将文件 ...

  8. js,replace() 和 正则表达式(regular expression)

    repalce() 只能替换字符串中的匹配到的第一个字符或者字符串 正则表达式   替换多个字符或者字符串 注意:一些数字型的字符串使用replace() 时要确保是字符串,而不是数字. 转换方法: ...

  9. 【转】SVN服务器搭建--Subversio与TortoiseSVN的配置安装

    转载地址:http://blog.csdn.net/xinxin19881112/article/details/6410263 1.  Subversio和TortoiseSVN 简介 Subver ...

  10. SIM卡应用-OPN,PLMN,SPN

    SIM卡应用 移动运营商已经将SIM卡用於很多不同的应用,下面列出了其中最主要的应 用∶ ·漫游应用∶确保手机可以在漫游之後选择缺省的运营商网络.一个SIM应用是可以在手机漫游到某个合作夥伴运营商网络 ...