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

花了这么长才过...感谢想出9进制的大牛

Posted by YangJie08281081 at 2010-04-10 20:36:06 on Problem 2719
真汗,水平不够啊...转成9进制一下就好了...
#include <iostream>
#include <string>
#include <math.h>
#include <sstream>
using namespace std;

int main()
{
	long num;
	stringstream ss;
	while(cin >> num && num != 0)
	{
		string s;
		ss << num;
		ss >> s;
		ss.clear();
		long sum = 0;
		for(int i = 0; i < s.length(); i++)
		{
			char tmp = s.at(i);
			long tmp2 = atoi(&tmp);
			if(tmp2 >= 4)
			{
				tmp2--;
			}
			sum += tmp2 * pow(9.0, (double)s.length() - i - 1);
		}
		cout << atoi(s.c_str()) << ": " << sum << 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