HDU 4278 Faulty Odometer [模拟]

把乱了以后的数码映射到真实的数码,然后就8进制转10进制。


代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
inline int Rint() { int x; scanf("%d", &x); return x; }
inline int max(int x, int y) { return (x>y)? x: y; }
inline int min(int x, int y) { return (x<y)? x: y; }
#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(x) for(int i=0; i<(x); i++)
typedef long long int64;
#define INF (1<<30)
const double eps = 1e-8;
#define bug(s) cout<<#s<<"="<<s<<" "

#define MAXN 20
char a[MAXN];
int bak;

int b[] = { 0, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8 };

int main()
{
	while(scanf("%s", a)!=-1)
	{
		if(a[0] == '0') break;
		bak = 0;
		for(int i=0; a[i]; i++)
		{
			bak = bak*10+a[i]-'0';
			a[i] = b[a[i]-'0']+'0';
		}
		int ans;
		sscanf(a, "%o", &ans);
		printf("%d: %d\n", bak, ans);
	}
}

//%o


阅读更多
换一批

没有更多推荐了,返回首页