题目1 : 有歧义的号码
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
-
10
样例输出 -
6 9
描述
小Hi参加了一场大型马拉松运动会,他突然发现面前有一位参赛者背后的号码竟然和自己一样,也是666。仔细一看,原来那位参赛者把自己号码帖反(旋转180度)了,结果号码999看上去变成了号码666。
小Hi知道这次马拉松一共有N名参赛者,号码依次是1~N。你能找出所有可能因为贴反而产生歧义的号码吗?
一个号码K可能产生歧义当且仅当反转之后的号码是合法的数字K',并且满足1 ≤ K' ≤ N且K' ≠ K。
例如:
3没有歧义,因为贴反之后不是合法的数字。
100没有歧义,因为001以0开头,不是合法号码。
101也没有歧义,因为贴反之后还是101本身。
假设N=10000000,则1025689有歧义,因为贴反之后变成6895201。如果N=2000000,则1025689没有歧义,因为6895201大于N。
输入
一个整数N。(1 ≤ N ≤ 100000)
输出
从小到大输出1~N之间所有有歧义的号码。每个号码一行。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
int change[10];
int N;
int calculate(int num){
if(num%10==0)return 0;
int res=0;
int ccc=num;
while(num>0){
res*=10;
if(change[num%10]==-1)return 0;
res+=change[num%10];
num/=10;
}
return res;
}
bool ans[100009];
void solve(){
for(int i=1;i<=N;i++){
int cur=calculate(i);
if(cur!=0&&cur>=1&&cur<=N&&cur!=i){
ans[i]=1;
}
else ans[i]=0;
}
}
int main(){
memset(change,-1,sizeof(change));
cin>>N;
change[0]=0;
change[1]=1;
change[2]=2;
change[5]=5;
change[6]=9;
change[8]=8;
change[9]=6;
solve();
for(int i=1;i<=N;i++){
if(ans[i]==1)printf("%d\n",i);
}
return 0;
}
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' |_/ |
// \ .-\__ '-' ___/-. /
// ___'. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' >' "".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `_. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/___.-`___.-'=====
// `=---='
//
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// 佛祖保佑 永无BUG
//
//
//