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组成的数字是幸运数字,现在要你求一共有多 ...
 
随机推荐
- 【海岛帝国系列赛】No.1 海岛帝国:诞辰之日
			
50111117海岛帝国:诞辰之日 [试题描述] YSF自从上次“被盗投降”完(带着一大堆债)回去以后,YSF对“海盗”怀念至今,他想要建立一个“药师傅”海岛帝国. 今天,他要像“管理部”那样去探寻 ...
 - 在线白板,基于socket.io的多人在线协作工具
			
首发:个人博客,更新&纠错&回复 是昨天这篇博文留的尾巴,socket.io库的使用练习,成品地址在这里. 代码已经上传到github,传送门.可以开俩浏览器看效果. 现实意义是俩人在 ...
 - Unable to resolve target 'android-19'
			
修改两个地方,解决上面的问题
 - PHP人民币金额数字转中文大写的函数
			
<?php header("Content-Type:text/html;charset=utf-8"); error_reporting(2); function cny( ...
 - 鸟哥的linux私房菜学习记录之例行性工作
 - innodb内部的并发线程
			
1. innodb_thread_concurrency innodb有一系列的计数器来统计和控制内部的工作线程.其中最重要的一个是innodb_thread_concurrency,和它相关的inn ...
 - android 开发中的常见问题
			
Android studio 使用极光推送, 显示获取sdk版本失败 在 build.gradle(Module.app) 添加 android { sourceSets.main { ...
 - KindEditor图片批量上传
			
KindEditor编辑器图片批量上传采用了上传插件swfupload.swf,所以后台上传文件方法返回格式应为JSONObject的String格式(注). JSONObject格式: JSONOb ...
 - linux内核中异步通信机制--信号处理机制【转】
			
转自:http://blog.csdn.net/lu_embedded/article/details/51131663 什么是异步通信?很简单,一旦设备准备好,就主动通知应用程序,这种情况下应用程序 ...
 - printf,sprintf,vsprintf 区别【转】
			
转自:http://blog.csdn.net/anye3000/article/details/6593551 有C语言写作历史的程序员往往特别喜欢printf 函数.即使可以使用更简单的命令(例如 ...