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组成的数字是幸运数字,现在要你求一共有多 ...
随机推荐
- win7 IIS发布项目遇到的问题
问题一: HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. 1.依次打开控制面板 ...
- [tp3.2.1]大D构建模型
使用大(写字母)D方法: 如果,在默认到Home模块下面找不到UserModel模块,那么就会到Common模块下去找. 而如果此时在Common模块下还是找不到UserModel,那就会调用Mode ...
- asp.net中获得客户端的IP地址
asp.net中获得客户端的IP地址 因为要在项目中取到客户端IP,在网上搜了下相关资料,其中有一篇文章总结的比较详细,这里就把一些我用的上总结一下 方便以后查阅. 通常我们都通过下面的代码获得IP ...
- :root
概述 选择该文档的根元素. 在HTML中,文档的根元素,和$(":root")选择的元素一样, 永远是<html>元素. 示例 设置<html>背景颜色为黄 ...
- android 弹幕效果demo
记得之前有位朋友在我的公众号里问过我,像直播的那种弹幕功能该如何实现?如今直播行业确实是非常火爆啊,大大小小的公司都要涉足一下直播的领域,用斗鱼的话来讲,现在就是千播之战.而弹幕则无疑是直播功能当中最 ...
- java多线程中的生产者与消费者之等待唤醒机制@Version1.0
一.生产者消费者模式的学生类成员变量生产与消费demo,第一版1.等待唤醒: Object类中提供了三个方法: wait():等待 notify():唤醒单个线程 notify ...
- 使用Jconsole监控weblogic的配置方法
在项目中发现full gc非常频繁.达到了每分钟13次.我怀疑可能会有内存泄露.于是在晚上找了内存泄露的资料. 内存长期占用并导致系统不稳定一般有两种可能: 1. 对象被大量创建而且被缓存,在旧的对象 ...
- html5 canvas 笔记二(添加样式和颜色)
色彩 Colors fillStyle = color 设置图形的填充颜色. strokeStyle = color 设置图形轮廓的颜色. 透明度 Transparency globalAlpha = ...
- 30、springmvc
第一章回顾JavaWeb中的MVC设计模式 1)MVC这种设计模式,不光运用于Web领域,而且也能用于非Web领域 2)今天说的MVC特指一种表现层设计模式,不限于Java语言 第二章回顾struts ...
- JavaEE基础(九)
1.面向对象(多态的概述及其代码体现) A:多态(polymorphic)概述 事物存在的多种形态 B:多态前提 a:要有继承关系. b:要有方法重写. c:要有父类引用指向子类对象. C:案例演示 ...