hiho 1623 有歧义的号码 [Offer收割]编程练习赛35 Problem A

题目1 : 有歧义的号码

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

小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之间所有有歧义的号码。每个号码一行。

样例输入
10
样例输出
6
9
水题。打表就可以。

#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
//
//
//







  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值