【C++】OJ139

#include<iostream>
#include<string>
using namespace std;
string transfer(string s){
	int i = 0;
	for(i = 0;i<s.length();i++){
		if(s[i]=='$')
			break;
	}
	string t = "";
	for(int j = i+1;j<s.length();j++){
		t += s[j];
	}
	return t;
}
double tran(string t){
	int k = 0;
	int to = 0;
	int n = 0;
	while(k<t.length()){
		n = (int)t[k]-48;
		for(int j = 0;j<t.length()-k;j++){
			n *= 10;
		}
		to += n;
	}
	return (double)to/100;
}
bool st(string s1,string s2){
	int k = s2.length();
	string u = "";
	for(int i = 0;i<k;i++){
		u += s1[i];
	}
	if(u==s2)
		return true;
	else
		return false;
}
string sub(string s1,string s2){
	int k = s2.length();
	string u = "";
	for(int i = k;i<s1.length();i++){
		u += s1[i];
	}
	return u;
}
int main(){
	string number[5] = {""};
	string local[5] = {""};
	int j = 0;
	double per[5] = {0.00};
	cin >> number[j];
	cin >> local[j];
	while(number[j]!="000000"){
		j++;
		cin >> number[j];
		cin >> local[j];
		per[j] = tran(transfer(local[j]));
	}
	j--;
	int k = 0;
	string num[10] = {""};
	int mi[10] = {0};
	double perm[10] = {0.00};
	string real[10] = {""};
	string belong[10] = {""};
	double t[10] = {0.00};
	cin >> num[k];
	cin >> mi[k];
	while(num[k]!="#"){
		k++;
		cin >> number[k];
		cin >> mi[k];
		real[k] = number[k];
		for(int x = 0;x<j;x++){
			if(st(num[k],number[x])==true){
				perm[k] = per[x];
				real[k] = sub(number[k],num[x]);
				t[k] += per[x]*mi[k];
				belong[k] = local[x];
				break;
			}
		}
	}
	k--;
	for(int y = 0;y<k;y++){
		cout << num[y]<<"  ";
		if(belong[y]!=""){
			cout << belong[y]<<"  ";
		}
		else{
			if((num[y])[0]=='0')
			    cout << "Unknown"<<"  ";
			else
				cout << "Local"<<"  ";
		}
		cout <<real[y]<<"  ";
		cout <<mi[y]<<"  ";
		if(belong[y]==""&&(num[y])[0]=='0')
			cout<<"         ";
		else
		    cout <<per[y]<<"  ";
		cout <<t[y]<<endl;
	}
}

点赞