萌新求教,无法退出程序是为何,我这个输出格式对吗?
查看原帖
萌新求教,无法退出程序是为何,我这个输出格式对吗?
554830
rabbitzph楼主2021/8/23 22:38
#include<iostream>
int m,n,cntm,cntn,cntr= 0;
using namespace std;
int main(){
	int n = 0;
	int sum = 0;
	int res = 0;
	int t1 = 0;
	int t2 = 0;
	int t3 = 0;
	int temp = 0;
	cin>>n;
	for(int x = 1;x<=n;x++){//控制循环次数 
		cntm=0;
		cntn=0;
		cntr=0;
		string str,str1;
		cin>>str;
		if(str[0]!=97&&str[0]!=98&&str[0]!=99){//判断是否输入了a,b,c ,若不是输入了a,b,c,强制使得这轮的运算符于上一轮相同  
			sum = 0;
			for(int i = 0;i<str.size();i++){ 
				if(i==0) temp = str.size();
				for(int u =1;u<temp;u++){
					str[i]*=10;
				}
				sum+=str[i];
			}
			m = sum;
			cin>>n;
			str = str1;
		}
		else{//若输入了a,b,c,正常输入后两个数字 
			str1 = str;
			cin>>m>>n;																		
		}
		t1=m;
		t2=n;
		while(t1>0){//计算位数 
			t1/=10;cntm++;
		}
		while(t2>0){
			t2/=10;cntn++;
		}
		if(str[0]=='a'){
			t3 = res = m+n;
			while(t3>0) t3/=10,cntr++;	
			cout<<m<<"+"<<n<<"="<<res<<endl;
			cout<<cntr+cntm+cntn+2<<endl;
		}
		else if(str[0] =='b'){
			t3 = res = m - n;
			t3 = labs(t3);
			while(t3>0) t3/=10,cntr++;
			cout<<m<<"-"<<n<<"="<<res<<endl;
			cout<<cntr+cntm+cntn+2<<endl;
		}
		else{
			t3 = res = m * n ;
			while(t3>0) t3/=10,cntr++;
			cout<<m<<"*"<<n<<"="<<res<<endl<<cntr+cntm+cntn+2<<endl;
		}	
	
	}
	return 0 ;

}
2021/8/23 22:38
加载中...