全re了,求大佬指点
查看原帖
全re了,求大佬指点
343874
hitwh2190400207楼主2020/5/22 21:36
#include <iostream>
#include <string>
#include<cstdio> 
#include<vector>
#include <sstream>
using namespace std;
class A
{
private:
    string s,a,b,t;
    int n;
    vector<string> m;
    vector<string>::iterator p;
public:
	A()
	{
		cin>>n;
		getchar();
		while(n--) 
		{ 	
			getline(cin,s);
			m.push_back(s);
		}
	}
	int str_num(string s)
	{
		int n;
		stringstream ss;
		ss<<s;
		ss>>n;
		return n;	
	}
	string num_str(int n)
	{
		string temp;
		stringstream ss;
		ss<<n;
		ss>>temp;
		return temp;
	}
	void handle()
	{
		char first=' '; 
		int pos;
		p=m.begin();
		while(p!=m.end()) 
		{
			s=(*p);
			pos=0;
			if(!isdigit(s[0])) 
			{
	            pos = s.find(' ',pos+2);
	            a = s.substr(2,pos-2);
	            b = s.substr(pos+1);
	            first = s[0];    
	        } 
			else 
			{
	            pos = s.find(' ',pos);
	            a = s.substr(0,pos);
	            b = s.substr(pos+1);
	        }
	        if(first == 'a')
			{
	            t = a + "+" + b + "=" + num_str(str_num(a) + str_num(b));
	            cout<<t<<endl;
	            cout<<t.size()<<endl;
	        } 
	        else if(first == 'b') 
			{
	            t= a + "-" + b + "=" + num_str(str_num(a) - str_num(b));
	            cout<<t<<endl;
	            cout<<t.size()<<endl;
	        }
	        else if(first == 'c') 
			{
	            t= a + "*" + b + "=" + num_str(str_num(a) * str_num(b));
	            cout<<t<<endl;
	            cout<<t.size()<<endl;
	        } 
	        p++;
		}
	}      
}; 
	
int main()
{
	A t;
	t.handle();
    return 0;
}
2020/5/22 21:36
加载中...