How Much Memory Your Code Is Using? Gym - 101955J

Posted Jozky86

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How Much Memory Your Code Is Using? Gym - 101955J相关的知识,希望对你有一定的参考价值。

How Much Memory Your Code Is Using? Gym - 101955J

题意:

t组数据,每组数据会有n个定义类型的方式,给你每个类型所占字节,问一共占了多少字节,最终答案按照Kibibyte单位输出,并向上取整

题解:

直接模拟就行,记得判断定义数组的情况,模拟题,全场最好做的题

代码:

#include <bits/stdc++.h>
using namespace std;
int k;
int n;
int cnt=0;
int main()
{
    scanf("%d",&k);
    while(k--){
        long long ans=0;
        scanf("%d\\n",&n);
        string a;
        while(n--){
        getline(cin,a);
        if(strstr(a.data(),"[")&&strstr(a.data(),"]")){
            int bas=0;
            if(strstr(a.data(),"long long ")){
                bas=8;
            }
            else if(strstr(a.data(),"long double ")){
                bas=16;
            }
            else if(strstr(a.data(),"bool ")){
                bas=1;
            }
            else if(strstr(a.data(),"char ")){
                bas=1;
            }
            else if(strstr(a.data(),"__int128 ")){
                bas=16;
            }
            else if(strstr(a.data(),"int ")){
                bas=4;
            }
            else if(strstr(a.data(),"double ")){
                bas=8;
            }
            else if(strstr(a.data(),"float ")){
                bas=4;
            }

            string kk;
            int f=0;
            for(auto i:a){
                if(i==']'){
                    f=0;
                }
                if(f==1){
                    kk.push_back(i);
                }
                if(i=='['){
                    f=1;
                }

            }
            int pp=atoi(kk.data());
            ans=ans+(long long)pp*bas;
        }
        else{
            if(strstr(a.data(),"long long ")){
                ans+=8;
            }
            else if(strstr(a.data(),"long double ")){
                ans+=16;
            }
            else if(strstr(a.data(),"bool ")){
                ans+=1;
            }
            else if(strstr(a.data(),"char ")){
                ans+=1;
            }
            else if(strstr(a.data(),"__int128 ")){
                ans+=16;
            }
            else if(strstr(a.data(),"int ")){
                ans+=4;
            }
            else if(strstr(a.data(),"double ")){
                ans+=8;
            }
            else if(strstr(a.data(),"float ")){
                ans+=4;
            }

        }
        }
        printf("Case #%d: ",++cnt);
        if(ans%1024==0){
            printf("%d\\n",ans/1024);
        }
        else{
            ans=ans/1024;
            ans++;
            printf("%d\\n",ans);
        }
    }
    return 0;
}

以上是关于How Much Memory Your Code Is Using? Gym - 101955J的主要内容,如果未能解决你的问题,请参考以下文章

How to store your password for code

How much do we need to learn to be a Self-driving Car Engineer?

How to change your password of your mysql account in WampServer

How to order your eggs?

How to handle your webdriver exceptions

How to Exceed Your Goals in 2016