Untitled

 avatar
ducsieumanh1hitlanamguku
plain_text
20 days ago
728 B
4
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
string a[1000];
int n;
int main() {
	cin>>n;
	for (int i=1;i<=n;i++) {
		cin>>a[i];
	}
	for (int i=1;i<=n;i++) {
		int prev=0;
		int aft=0;
		int xnx=0;
		while (a[i][xnx] !='+'&&a[i][xnx]!='-'&&a[i][xnx]!='*') {
			xnx++;	
		}
		int dem=0;
		while (xnx>0) {
			prev+=(a[i][xnx-1]-48)*pow(10,dem);
			dem++;
			a[i].erase(xnx-1,1);
			xnx--;
		}
		dem=0;
		while (a[i].size()>1) {
			aft+=(a[i][a[i].size()-1]-48)*pow(10,dem);
			dem++;
			a[i].erase(a[i].size()-1,1);
		}
		if (a[i]=="+") cout<<prev+aft<<endl;
		else if (a[i]=="-") cout<<prev-aft<<endl;
		else if (a[i]=="*") cout<<prev*aft<<endl;
		else if (a[i]=="/") cout<<prev/aft<<endl;
	}
}
Leave a Comment