社区讨论

WA30分,测试数据本地能过

P1957口算练习题参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lyvl4ohy
此快照首次捕获于
2024/07/21 21:19
2 年前
此快照最后确认于
2024/07/21 23:22
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int n;
int ax,bx;
char way;
char vec;
int numc;
std::string x;
int num(int a){
	int b=0;
	while(a!=0){
		a/=10;
		b++;
	}
	return b;
}
int turn (string a){
	int ans=0;
	int x=a.length();
	int cnt=1;
	for (int i=x-1;i>=0;i--){
		ans+=(a[i]-'0')*cnt;
		cnt*=10;
	}
	return ans;
}
string a;
string b;
void cut(string x){
	int cd=x.length();
	for(int i=0;i<cd;i++){
		if(x[i]>='0'&&x[i]<='9'){
			a+=x[i];
		}
		if(x[i]==' '&&x[i-1]>='0'&&x[i-1]<='9'){
			for(int j=i+1;j<cd;j++) b+=x[j];
			break;
		}
	}
}

int main(){
	cin>>n;
	for(int i=0;i<=n;i++){
		std::getline(std::cin,x);
		a="";
		b="";
		cut(x);
		ax=turn(a);
		bx=turn(b);
		int numa=num(ax);
		int numb=num(bx);
		if(x[0]=='a'||x[0]=='b'||x[0]=='c'){
		if(x[0]=='a'){
			cout<<a<<"+"<<b<<"="<<ax+bx<<endl;
			numc=num(ax+bx);
			cout<<numa+numb+numc+2<<endl;
		}
		if(x[0]=='b'){
			cout<<a<<"-"<<b<<"="<<ax-bx<<endl;
			if(ax>bx) cout<<num(ax)+num(bx)+num(ax-bx)+2;
			else cout<<num(ax)+num(bx)+num(abs(ax-bx))+3;
		}
		if(x[0]=='c'){
			cout<<a<<"*"<<b<<"="<<ax*bx<<endl;
			cout<<num(ax)+num(bx)+num(ax*bx)+2<<endl;
		}
		vec=x[0];
			}
		else {
		if(vec=='a'){
			cout<<a<<"+"<<b<<"="<<ax+bx<<endl;
			cout<<num(ax)+num(bx)+num(ax+bx)+2<<endl;
		}
		if(vec=='b'){
			cout<<a<<"-"<<b<<"="<<ax-bx<<endl;
			if(ax>bx) cout<<num(ax)+num(bx)+num(ax-bx)+2;
			else cout<<num(ax)+num(bx)+num(abs(ax-bx))+3;
		}
		if(vec=='c'){
			cout<<a<<"*"<<b<<"="<<ax*bx<<endl;
			cout<<num(ax)+num(bx)+num(ax*bx)+2<<endl;
		}
		}
	}
	return 0; 
} 
WA3,4,5,6,8,9,10

回复

0 条回复,欢迎继续交流。

正在加载回复...