首页 > ACM题库 > HDU-杭电 > HDU 2864- “Base B”[解题报告]HOJ
2014
02-17

HDU 2864- “Base B”[解题报告]HOJ

“Base B”

问题描述 :

AekdyCoin is so fond of math.He loves Number.He knows how to express a non-negative number into P base.Say,he knows that the number 71 in 2 Base is exactly “1000111”. But AekdyCoin doesn’t think it’s a proper way to express a number.AekdyCoin want to creat the “Base B”,whose digits’ value is not only equal or larger than A,but also smaller than A+B.For example,if A = 1,B = 5,then AekdyCoin could express number 65 in “Base 5” ,it is “225” definitely .(But Not “230”,0 is out of the range [1,5]!)
AekdyCoin is quite exciting about his “invention”,now he hopes that you could write a program for him which could help him to express a number in “Base B”.

输入:

The input consists of several test cases.

Every case has only three integers indicating N,A,B (0<=N<=10^9,0<=A<=100,2<=B<=100)

输出:

The input consists of several test cases.

Every case has only three integers indicating N,A,B (0<=N<=10^9,0<=A<=100,2<=B<=100)

样例输入:

65 1 5
15 0 2

样例输出:

Case 1: 2 2 5
Case 2: 1 1 1 1
Hint
Hint: In case 1, 65 = 2 * 5^2 + 2 * 5 + 5 * 1,and all digits are in the range[1,5].

#include <iostream>

using namespace std;

int main()
{
 int N,A,B,cases=0;
 while (cin>>N>>A>>B)
 {
 cases++;
 int i=0,dig[100];
 while (N!=0)
 {
 if (N%B<A)
 {
 dig[i]=N%B+B;
 N=N/B-1;
 }
 else
 {
 dig[i]=N%B;
 N=N/B;
 }
 i++;
 }
 cout<<"Case "<<cases<<":";
 for (int j=i-1;j>=0;j--)
 {
 cout<<" "<<dig[j];
 }
 cout<<endl;
 }
 return 0;
}

  1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术,也不懂什么是算法,从而也不要求程序员懂什么算法,做程序从来不考虑性能问题,只要页面能显示出来就是好程序,这是国内的现状,很无奈。