Lucky TicketTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 146A
Description
petya loves lucky numbers very much. Everybody knows that lucky numbers is positive integers whose decimal record contains only the lucky Digits 4 and 7. For example, Numbers 47, 744, < Span class= "TEX-FONT-STYLE-BF" >4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket have a number that is a positive integer. Its length equals n (n are 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 th E First n /2 digits) equals the sum of digits in the second half (the sum of the last n /2 dig ITS). Check if the given ticket is lucky.
Input
The first line contains a even integer n(2≤ n ≤50)-the length of the ticket number that nee DS to is 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.
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 intMain ()6 {7 Chara[ the];8 intI,j,n;9 while(SCANF ("%d", &n)! =EOF)Ten { One intflg=1, s1=0, s2=0; Ascanf"%s", a); - for(i=0; i<n;i++) - { the if(i<n/2) -s1=s1+a[i]-'0'; - Else -s2=s2+a[i]-'0'; + if(a[i]=='4'|| a[i]=='7') - { +flg=1; A } at Else - { -flg=0; - Break; - } - } in //printf ("%d%d\n", s1,s2); - if(s1!=S2) toflg=0; + if(FLG) -printf"yes\n"); the Else *printf"no\n"); $ }Panax Notoginseng return 0; -}View Code
Codeforces 146A Lucky Ticket