leyouyuan @ 2024-08-22 21:50:59
#include<cstdio>
#include<iostream>
#include<cstring>
#define _ADD 1
#define _SUB 2
#define _MUL 3
using namespace std;
void mygetline(char *s)
{
char c='0';
while((c=getchar())!='\n'){
*s=c;
s++;
}
*s='\0';
}
int switchmode(char c)
{
if(c=='a') return _ADD;
if(c=='b') return _SUB;
if(c=='c') return _MUL;
return 0;
}
char opr(int m)
{
if(m==_ADD)return '+';
if(m==_SUB)return '-';
if(m==_MUL)return '*';
return 0;
}
int result(int m,int a,int b)
{
if(m==_ADD)return a+b;
if(m==_SUB)return a-b;
if(m==_MUL)return a*b;
return 0;
}
int main()
{
int mode;
char s [40];
char res [40];
char *t;
int a,b;
int n;
cin>>n;
for(int i = 1;i<=n;i++)
{
mygetline(s);
t=s;
if(*t>='a'&&*t<'z')
{
mode=switchmode(*t);
t+=2;
}
sscanf(t,"%d %d",&a,&b);
sprintf(res,"%d%c%d=%d\n",a,opr(mode),b,result(mode,a,b));
cout<<res<<endl;
cout<<strlen(res)<<endl;
}
}
如图所示,下载到的第一组数据中,输入为
1
a 99 999
输出是
99+999=1098
11
我看都是对的啊!
by Ke9_qux @ 2024-08-22 21:56:46
@leyouyuan 警惕'\r'
by Ke9_qux @ 2024-08-22 21:58:14
@leyouyuan 而且你在第62行有多余换行
by Ke9_qux @ 2024-08-22 21:59:06
问题还有点多
by leyouyuan @ 2024-08-22 22:01:25
@Ke9_qux \r是什么意思,如何解决
by Ke9_qux @ 2024-08-22 22:03:39
windows下的换行符是\n\r
,与luogu评测机系统不兼容,在第12行加判断
by Ke9_qux @ 2024-08-22 22:04:12
打错了,是\r\n
by leyouyuan @ 2024-08-22 22:04:25
还有个问题就是"read 0,expected 9",感觉每一个数字都被识别成0了 现在求解决
by Ke9_qux @ 2024-08-22 22:05:04
好像本题数据没有这个锅
by Ke9_qux @ 2024-08-22 22:08:07
@leyouyuan 第51行输入的时候要吞换行
by Ke9_qux @ 2024-08-22 22:08:36
可以写scanf("%d\n",&n);