zoukankan      html  css  js  c++  java
  • CodeForces 146A Lucky Ticket

    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

    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 namespace std;
     5 int main()
     6 {
     7     char a[105];
     8     int i,j,n;
     9     while(scanf("%d",&n)!=EOF)
    10     {
    11         int flg=1,s1=0,s2=0;
    12         scanf("%s",a);
    13         for(i=0;i<n;i++)
    14         {
    15             if(i<n/2)
    16                 s1=s1+a[i]-'0';
    17             else
    18                 s2=s2+a[i]-'0';
    19             if(a[i]=='4' || a[i]=='7')
    20             {
    21                 flg=1;
    22             }
    23             else
    24             {
    25                 flg=0;
    26                 break;
    27             }
    28         }
    29         //printf("%d %d
    ",s1,s2);
    30         if(s1!=s2)
    31             flg=0;
    32         if(flg)
    33             printf("YES
    ");
    34         else
    35             printf("NO
    ");
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    object对象
    addEventListener 和 attachEvent
    BOM常用对象
    动态原型
    鼠标移动图片放大效果(兼容IE8、多图)
    伪元素:before和:after
    javascript/js 判断是否安装flash player插件,提示安装方法。
    Form表单值转换为[{name:'',value}]键值对
    [转][网站、云服务与虚拟机]弄清负载均衡的机制
    C# Lazy Initialization
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771482.html
Copyright © 2011-2022 走看看