给出一个八进制的正整数x,求x的十六进制表示中A、B、C的个数。
Description
多组测试数据(不超过1000组)。
每一行一个八进制非负整数x(数据范围保证在long long int范围内)。
每一行一个八进制非负整数x(数据范围保证在long long int范围内)。
Input
每组测试数据输出A、B、C出现的次数。
Output
1
2
|
5274
52746100
|
Sample Input
1
2
|
1 1 1
1 1 2
|
/*题解:
错误点:
输入的x(八进制)可能超long long 范围,十进制不会超,用字符串就可以了
pow返回值超范围,强制转换一下就好了
*/
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
char str[1000];
while (scanf("%s",str)!=EOF)
{
unsigned long long int ss = 0;
for (int i = 0; i < strlen(str); i++)
{
ss += (str[i] - '0')*(unsigned long long)pow(8, strlen(str) - i - 1);
}
int A = 0, B = 0, C = 0;
while (ss > 0)
{
int tt = ss % 16;
if (tt == 10)
{
A++;
}
else if(tt==11)
{
B++;
}
else if (tt == 12)
{
C++;
}
ss /= 16;
}
cout << A << ' ' << B << ' ' << C << "\r\n";
}
return 0;
}