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
  • 相关阅读:
    4、Cocos2dx 3.0三,找一个小游戏开发Hello World 分析
    Android Bluetooth开发
    详细解析BluetoothAdapter的详细api
    Android 蓝牙( Bluetooth)耳机连接分析及实现
    [Andriod官方API指南]连接之蓝牙
    Android蓝牙A2dp profile的使用
    Android中文API(129) —— AudioManager
    Android中的Audio播放:控制Audio输出通道切换
    JAVA ANDROID SOCKET通信检测(SERVER)连接是否断开
    Android Xfermode 实战 实现圆形、圆角图片
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771482.html
Copyright © 2011-2022 走看看