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组成的数字是幸运数字,现在要你求一共有多 ...
随机推荐
- 夺命雷公狗—angularjs—23—copy拷贝对象
copy这在angularjs中是一个拷贝对象的方法: <!DOCTYPE html> <html lang="en" ng-app="myapp&qu ...
- Deep Learning 深度学习 学习教程网站集锦
http://blog.sciencenet.cn/blog-517721-852551.html 学习笔记:深度学习是机器学习的突破 2006-2007年,加拿大多伦多大学教授.机器学习领域的泰斗G ...
- IE已经被抛弃,但是不能遗忘
虽然IE的兼容问题,在我写这篇文章的时候基本已经被抛弃了,但是我觉得还是应该了解一下最基本的解决办法. 就像中国的历史已经过去,但是我们不能忘记一样的. 逐个版本解决法 .bb{ background ...
- 8. 星际争霸之php设计模式--享元模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 技术总监和CTO的区别 浅谈CTO的作用----软件公司如何开源节流(一)[转]
我一直在思考软件公司如何开源节流.当然,老板也在思考开源节流.当然,老板思考的开源节流在公司运营层面上,而我作为CTO,我考虑的则是在产品运营角度上来思考这个问题.否则,一个软件公司,它的生存与发展就 ...
- 嵌套错误Inline markup blocks (@<p>Content</p>) cannot be nested. Only one level of inline markup is allowed
例子: @{Html.Telerik().Splitter().Name("MainSplitter") .Orientation(SplitterOrientation.Vert ...
- remoting方式
1. WebService跨平台,跨防火墙,但是很抱歉,基于xml速度慢2. RMI(java)/Remoting(.net)平台相关,基于二进制序列化,速度快.3.dcom(com+)spring提 ...
- UI优化
进入正题,我们这一篇文章会提到为什么使用HierarchyViewer,怎么使用HierarchyViewer,后者内容会多一下. 为什么使用HierarchyViewer 不合理的布局会使我们的应用 ...
- Java的多线程+Socket
客户端: package com.wulala; import java.io.FileOutputStream;import java.io.IOException;import java.io.I ...
- arduino 蓝牙控制RGB LED灯
/* 日期:2016.9.2 功能:arduino 蓝牙控制RGB LED灯 元件: 跳线公公头 * 8 rgbled, 220欧电阻 蓝牙模块 接线: 蓝牙模块VCC,GND分别接5V,GND;TX ...