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;
}