CodeForces 146A 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
2
47
NO
4
4738
NO
4
4774
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的更多相关文章
- Codeforces 121A Lucky Sum
Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- 数据结构(线段树):CodeForces 145E Lucky Queries
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元
题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...
- codeforces 630C - Lucky Numbers 递推思路
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦 ...
- Codeforces 145E Lucky Queries 线段树
Lucky Queries 感觉是很简单的区间合并, 但是好像我写的比较麻烦. #include<bits/stdc++.h> #define LL long long #define f ...
- CodeForces 146E Lucky Subsequence(组合数+DP)
题目描述 Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers w ...
- CodeForces 122G Lucky Array(一脸懵逼的树状数组)
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal re ...
- codeforces 110E Lucky Tree
传送门:https://codeforces.com/contest/110/problem/E 题意:给你一颗树,节点与节点之间的边有一个边权,定义只由4和7组成的数字是幸运数字,现在要你求一共有多 ...
随机推荐
- ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml)
我们都知道在使用WebApi的时候Controller会自动将Action的返回值自动进行各种序列化处理(序列化为json,xml等),但是如果Controller的自动序列化后的结果不是我们想要的该 ...
- sql2005镜像实现
-- =========================================== -- 无论是主体服务器.镜像服务器, 还是见证服务器 -- 除特别说明外,均需要保证下面的操作 ...
- 使用JWPlayer在网页中嵌入视频
首发:个人博客,持续更新和纠错 我一直以为在网页中嵌入视频是件复杂的事,一研究才知道原来非常简单. 实际就是在页面中嵌入个控件.社区里已有很多解决方案了.jwplayer是最受欢迎的(之一).控件包括 ...
- SQL SERVER索引
(一)深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录.微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引.簇集索引)和非聚 ...
- Oracle 10g dataguard broker 配置
环境: OS:rhel6.3_64bit DB:Oracle10gR2 ————————————————————————dataguard broker配置—————————————————————— ...
- COM编程之五 动静态链接
[1]静态链接 静态链接是指由链接器在链接时将库的内容加入到可执行程序中的做法. 链接器是一个独立程序,将一个或多个库或目标文件(先前由编译器或汇编器生成)链接到一块生成可执行程序. 函数和数据被编译 ...
- SslUtil
package com.eaju.util; import java.io.OutputStreamWriter;import java.net.URL;import java.net.URLConn ...
- tomcat监控脚本
工作所需,匆匆忙忙写了个监控tomcat的shell脚本,大概思路是这样的:先检测tomcat进程是否存在,如果不存在就启动,如果进程存在,检测页面返回码状态,如果是200就是正常,如果不是就重启. ...
- https笔记
TCP提供了可靠的,面向连接的字节流服务. 1)应用数据分割成TCP认为适合发送的数据块,通过MSS(最大数据包长度)来控制. 2)重传机制 3)对首部和数据进行校验 4)TCP对收到的数据进行排序, ...
- eclipse怎么设置字体大小
eclipse怎么设置字体大小