regime @ 2020-09-06 14:16:29
#include<bits/stdc++.h>
using namespace std;
int n;
char s[200001],last[200001],ch;
int main(){
// freopen("P1957 口算练习题.in","r",stdin);
// freopen("P1957 口算练习题.out","w",stdout);
ch=getchar(),getchar();
n=ch-'0';
for(int l=1;l<=n;l++){
gets(s);
int x=0,y=0,len=strlen(s);
if(s[0]>='0'&&s[0]<='9'){
int i;
for(i=0;s[i]>='0'&&s[i]<='9';i++)x=x*10+(s[i]-'0');
i++;
while(i<len){
y=y*10+(s[i]-'0');
i++;
}
// printf("%d %d\n",x,y);
}
else{
int i;
for(i=2;s[i]>='0'&&s[i]<='9';i++)x=x*10+(s[i]-'0');
i++;
while(i<len){
y=y*10+(s[i]-'0');
i++;
}
// printf("%d %d\n",x,y);
}
// printf("%d %d\n",x,y);
int k;
if(s[0]=='a')printf("%d+%d=%d\n",x,y,x+y),k=x+y;
if(s[0]=='b')printf("%d-%d=%d\n",x,y,x-y),k=x-y;
if(s[0]=='c')printf("%d*%d=%d\n",x,y,x*y),k=x*y;
if(s[0]>='0'&&s[0]<='9'){
if(last[0]=='a')printf("%d+%d=%d\n",x,y,x+y),k=x+y;
if(last[0]=='b')printf("%d-%d=%d\n",x,y,x-y),k=x-y;
if(last[0]=='c')printf("%d*%d=%d\n",x,y,x*y),k=x*y;
}
int ans;
if(s[0]>='a')ans=len-1;
else ans=len+1;
if(k<0)ans++,k*=-1;
while(k>0)k/=10,ans++;
if(l==n)printf("%d",ans);
else printf("%d\n",ans);
for(int i=0;i<len;i++)last[i]=s[i];
}
return 0;
}
by Spasmodic @ 2020-09-06 14:17:37
@regime 没删freopen?
by regime @ 2020-09-06 14:19:08
当然删了
by Smile_Cindy @ 2020-09-06 14:19:49
here
by regime @ 2020-09-06 14:23:41
为毛luoguIDE与我dev的结果不一样?
by entity @ 2020-10-28 22:11:41
@Alpha 洛谷IDE和我的DEV结果一样,但还是WA
by WeiqiWen2009 @ 2020-12-05 13:55:30
#include<bits/stdc++.h>
using namespace std;
int a,b,ans,n;
char c,a1[100];
int f(int ans)
{
int len=0;
if(ans<0)
{
len++;
}
if(ans==0)
{
len++;
}
while(ans!=0)
{
ans/=10;
len++;
}
return len;
}
int main()
{
//freopen("P1957_1.in","r",stdin);
//freopen("P1957.out","w",stdout);
cin>>n;
getchar();
for(int j=0;j<n;j++)
{
a=0;
b=0;
ans=0;
int len=2;
memset(a1,'\0',sizeof(a1));
gets(a1);
bool t1=false,t2=false;
for(int i=0;i<strlen(a1);i++)
{
if(a1[i]>='a'&&a1[i]<='z')
{
c=a1[i];
}
else if(a1[i]>='0'&&a1[i]<='9')
{
if(t2==false)
{
a=a*10+(int)(a1[i]-'0');
len++;
if(a1[i+1]==' ')
{
t2=true;
}
}
else if(t2==true)
{
b=b*10+(int)(a1[i]-'0');
len++;
}
}
}
switch(c)
{
case 'a':ans=a+b;
printf("%d+%d=%d\n",a,b,ans);
break;
case 'b':ans=a-b;
printf("%d-%d=%d\n",a,b,ans);
break;
case 'c':ans=a*b;
printf("%d*%d=%d\n",a,b,ans);
break;
}
len+=f(ans);
printf("%d\n",len);
}
return 0;
}
我也是