(2702 内存空间)dotcpp的在线提交有bug?

RT,在写完一道不难的题(蓝桥杯2022年第十三届决赛真题-内存空间(C/C++/Java组) - C语言网)后,拿去提交却显示答案错误。我怎么想也觉得没错。

打开具体的结果后,结果如上,明显是系统把最后一行数据都跳了

但是拿自己的电脑测并没问题,和标准输出是一样的。

所以有好心人知道是怎么回事吗?

代码如下

#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;
char a[1005];
int T;
string a1;
char *type[3]={"int","long","String"};
int sitype[3]={1024,1024*1024,1024*1024*1024};
char *last[4]={"GB","MB","KB","B"};
long long ans=0;
int main(){
    scanf("%d",&T);
    getchar();
    for(int p=1;p<=T;p++){
            getline(cin,a1);
            bool f=0;
            string temp=""; 
            for(int i=0;i<a1.size();i++){
      
                    if(!f){
                    temp+=a1[i];
                    if(temp==type[0]|temp==type[1]|temp==type[2]){
                        //TODO
                        f=1;
                    }                
                    continue;
                    }
                    if(temp==type[2]){
                        int temp1=0;int temp2=0;
                        for(int j=i;j<a1.size();j++){
                            if(a1[j]=='"'&&temp1==0){
                          
                                temp1=j;
                                
                                continue;
                            }
                            if(a1[j]=='"'&&temp1>0){
       
                                temp2=j;
                                ans+=(temp2-temp1-1);
                                temp1=0;temp2=0;
                            }
                            if(a1[j]==';'){
                                i=j;
                                f=0;
                                break;
                                
                            }
                        }
                        continue;
                    }
                    else if(a1[i]=='['&&a1[i+1]==']'){
                        int temp1=0;int temp2=0;
                        for(int j=i;j<a1.size();j++){
                            if(a1[j]=='['&&a1[j+1]!=']'){
                               temp1=j+1;
                            }
                            if(a1[j]==']'&&temp1>0){
                                temp2=j-1;
                                int ans1=0;
                                int k=0;
                                for(int l=temp2;l>=temp1;l--){                
                                    ans1+=pow(10,k)*(a1[l]-'0');
                                    k++;
                                }
                                if(temp==type[0])ans+=ans1*4;
                                else ans+=ans1*8;
                                temp1=0;temp2=0;
                          }
                          if(a1[j]==';'){
                                  i=j;
                                  f=0;temp1=0;temp2=0;
                                  break;
                                  }
                        }
                        continue;
                    }
                    else {
                     
                        int ans1=0;
                        for(int j=i;j<a1.size();j++){
                            if(a1[j]=='='){
                              ans1+=1; 
                            }
                            if(a1[j]==';'){
                            if(temp==type[0]){
                                ans+=4*ans1;
                            }
                            else ans+=ans1*8;
                            f=0;
                            break;
                            }
                        }
                        continue;
                    }
                
            }            
    }
    int la[4];
    la[0]=ans/sitype[2];
    ans-=sitype[2]*la[0];
    la[1]=ans/sitype[1];
    ans-=sitype[1]*la[1];
    la[2]=ans/sitype[0];
    ans-=sitype[0]*la[2];
    la[3]=ans;
    for(int i=0;i<=3;i++){
        if(la[i]>0){
            printf("%d",la[i]);
            printf("%s",last[i]);
            };
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值