easyf12 @ 2021-08-27 19:14:01
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main(){
int n,f;
cin>>n;
cin.ignore();
for(int k=1;k<=n;k++){
string line;
getline(cin,line);
if(line[0]=='a'||line[0]=='b'||line[0]=='c'){
int p,s1=0,s2=0;
for(int i=2;i<line.size();i++){
if(line[i]==' '){
p=i;
break;
}
else if(line[i]=='-'){
s1=-1;
}
else{
if(line[i-1]=='-')s1*=(line[i]-'0');
else s1=s1*10+(line[i]-'0');
}
}
for(int i=p+1;i<line.size();i++){
if(line[i]=='-'){
s2=-1;
}
else{
if(line[i-1]=='-')s2*=(line[i]-'0');
else s2=s2*10+(line[i]-'0');
}
}
if(line[0]=='a'){
f=1;
int x=s1+s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()-1+s;
cout<<s1<<'+'<<s2<<'='<<s1+s2<<endl<<l;
}
if(line[0]=='b'){
f=2;
int x=s1-s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()-1+s;
cout<<s1<<'-'<<s2<<'='<<s1-s2<<endl<<l;
}
if(line[0]=='c'){
f=3;
int x=s1*s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()-1+s;
cout<<s1<<'*'<<s2<<'='<<s1*s2<<endl<<l;
}
}
else if(line[0]!='a'&&line[0]!='b'&&line[0]!='c'){
int p,s1=0,s2=0;
for(int i=0;i<line.size();i++){
if(line[i]==' '){
p=i;
break;
}
else if(line[i]=='-'){
s1=-1;
}
else{
if(line[i-1]=='-')s1*=(line[i]-'0');
else s1=s1*10+(line[i]-'0');
}
}
for(int i=p+1;i<line.size();i++){
if(line[i]=='-'){
s2=-1;
}
else{
if(line[i-1]=='-')s2*=(line[i]-'0');
else s2=s2*10+(line[i]-'0');
}
}
if(f==1){
int x=s1+s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()+2+s;
cout<<s1<<'+'<<s2<<'='<<s1+s2<<endl<<l;
}
if(f==2){
int x=s1-s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()+2+s;
cout<<s1<<'-'<<s2<<'='<<s1-s2<<endl<<l;
}
if(f==3){
int x=s1*s2,s=0;
if(x<=0)s++;
while(x!=0){
x/=10;
s++;
}
int l=line.size()+2+s;
cout<<s1<<'*'<<s2<<'='<<s1*s2<<endl<<l;
}
}
if(k<n)cout<<endl;
}
return 0;
}
代码在上。我在洛谷IDE里运行是这样的: 而我在VS Code里运行却是这样的: 这是神马情况?蒟蒻求助!
by zbwcom @ 2021-08-27 19:15:17
你再用Devc++试试
by AlexandreLea @ 2021-08-27 19:16:05
是编译指令的问题吧,你本地编译的时候编译指令和luogu不同,因此不同。
by easyf12 @ 2021-08-27 19:16:54
@zbwcom Dev-C++对的
by zbwcom @ 2021-08-27 19:17:05
64+46=110
9
我的IDE是这样的,和VScode一样
by _l_l_l_l_l_ @ 2021-08-27 19:17:45
循环了再ignore几次?
by easyf12 @ 2021-08-27 19:20:25
我听说洛谷IDE是在Linux上运行的,本地是Windows,是这个原因吗
by Fgju @ 2021-09-05 02:43:18
cin.ignore()
的默认参数是(1,eof)来着……
也许你可以试试改参数?
by Grooth @ 2022-01-18 15:41:11
我的和你的一模一样,想问下你这问题解决了嘛
by Observe2 @ 2022-01-21 17:46:11
我也是一模一样