zoukankan      html  css  js  c++  java
  • Codeforces Round #339 (Div. 2) B. Gena's Code

    B. Gena's Code
    time limit per test
    0.5 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!

    There are exactly n distinct countries in the world and the i-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. Abeautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.

    Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

    Input

    The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line containsn non-negative integers ai without leading zeroes — the number of tanks of the i-th country.

    It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed 100 000.

    Output

    Print a single number without leading zeroes — the product of the number of tanks presented by each country.

    Examples
    input
    3
    5 10 1
    output
    50
    input
    4
    1 1 10 11
    output
    110
    input
    5
    0 3 1 100 1
    output
    0
    Note

    In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.

    In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.

    In sample 3 number 3 is not beautiful, all others are beautiful.

     题意:有n个数,其中n-1个数为完美数(只有1,0且1只出现一次,即为10的倍数)输出乘积   每个数位数小于1e6

     题解:每个数以字符串的形式输入到数组里,然后每个数去判定,如果为0,则直接输出0,如果为1,则continue,如果为完美数则保存0的个数,如果不为完美数,标记不完美数的长度和数字。最后不完美数没有的话输出一个1,有不完美数时输出不完美数在输出0的个数。

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    const int N=1e5+7;
    int  a[N],t[N]; 
    int main()
    {
        int n;
        cin>>n;
        int sum=0; 
        int k;
        int flag1=0;
        memset(t,0,sizeof(t)); 
        for(int i=1;i<=n;i++)
        {  
            string s;
            cin>>s;
            if(s=="0"){ 
                cout<<0<<endl;
                return 0;
             }
             if(s=="1")
                 continue; 
             memset(a,0,sizeof(a)); 
            a[0]=s.size();
               for(int j=1;j<=a[0];j++)
                a[j]=s[a[0]-j]-'0';   
             int k=0;
             int count=0;
             int count1=0;
             if(a[a[0]]==1)
                 count++; 
            for(int j=a[0]-1;j>=1;j--)
            {
                k++;
                if(a[j]==0)
                 count1++;
            }  
            if(count==1&&count1==k)
                sum+=k; 
            else 
            {
                 for(int j=a[0];j>=1;j--)
                 t[j]=a[j];
                 t[0]=a[0]; 
                 flag1=1; 
            } 
        }     
        if(!flag1)
            cout<<1;
        else {
            for(int j=t[0];j>=1;j--)
                cout<<t[j];
        } 
        for(int i=1;i<=sum;i++)
            cout<<0;
        cout<<endl; 
    } 
    漫天星辰,繁华时下。心中冷淡,一笑奈何。
  • 相关阅读:
    打印图片的属性和实现另存图片功能以及使用numpy
    opencv3.3 安装环境教程以及实现个图片读取功能
    在linux 创建网络会话和绑定两块网卡
    安装yum仓库
    C#添加错误日志信息
    关于使用宏将csv批量转换成xls的分享
    C#关于MySQL中文乱码问题
    无法启动iis express web服务器解决
    关于关闭WPS锁屏屏保及设置电脑自动关闭显示屏及休眠的分享
    为什么QQ能上却打不开网页呢?
  • 原文地址:https://www.cnblogs.com/Scalpel-cold/p/7217181.html
Copyright © 2011-2022 走看看