Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

真有。。。太恶心了

Posted by KatrineYang at 2016-11-08 03:36:52 on Problem 1489
In Reply To:输入有空行,需要过滤下。。。 Posted by:HEU_Archer at 2011-06-18 16:51:56
#include <iostream>
#include <string>
using namespace std;
long long int val(char c){
	switch(c){
		case '|': return 1;
		case 'n': return 10;
		case '9': return 100;
		case '8': return 1000;
		case 'r': return 10000;
		default: return 0;
	}
}
long long int parse(string s){
	long long int res = 0;
	long long int len = s.length();
	for(int i = 0; i < len; i++){
		res += val(s[i]);
	}
	return res;
}

string toString(long long int n){
	string res;
	bool first = 1;
	long long int n1=n%10,n10=(n/10)%10,n100=(n/100)%10,n1000=(n/1000)%10,n10000=(n/10000)%10;
	if(n1){
		while(n1--) res+="|";
		first=0;
	}
	if(n10){
		if(!first)res+=" ";
		while(n10--) res+="n";
		first=0;
	}
	if(n100){
		if(!first)res+=" ";
		while(n100--) res+="9";
		first=0;
	}
	if(n1000){
		if(!first)res+=" ";
		while(n1000--) res+="8";
		first=0;
	}
	if(n10000){
		if(!first)res+=" ";
		while(n10000--) res+="r";
	}
	return res;
}

int main() {
	string sa, sb;
	while(getline(cin,sa)){
		long long int a=parse(sa);
		if(!a)continue;
		getline(cin,sb);
		long long int b=parse(sb);
		long long int start = 1;
		while(start<=b){
			string sstart = toString(start);
			string sprod = toString(start*a);
			int l = sstart.length();
			cout << sstart;
			if((start & b) == start){
				cout << " *";
				for(int i = 0; i < 32-l; i++) cout << " ";
			}
			else{
				for(int i = 0; i < 34-l; i++) cout << " ";
			}
			cout << sprod << " " << endl;
			start <<= 1;
		}
		cout << "The solution is: " << toString(a*b) << " " << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator