蓝桥——商标倒放

// test.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include <stdio.h>
#include<sstream>
using namespace std;

void i2s(int n, string &s) {
    stringstream ss;
    ss << n;
    ss >> s;
}

int reverse(int n) {
    string s;
    int a;
    i2s(n, s);
    if (s[0] == '0')return -1;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '3' || s[i] == '4' || s[i] == '7')
            return -1;
        else if (s[i] == '6')s[i] = '9';
        else if (s[i] == '9')s[i] = '6';
    }
    int temp;
    for (int i = 0; i < s.length()/2; i++) {
        temp = s[i];
        s[i] = s[s.length() - i - 1];
        s[s.length() - 1 - i] = temp;
    }
    stringstream ss;
    ss << s;
    ss >> a;
    return a;
}

int main()
{

    //int a = reverse(1958);
    //cout << a;
    
    /*
    
    
    */
    int a8[10000] = { 0 };//存放赚了800多的
    int a2[10000] = { 0 };//存放赔了200多的
    int az = 0, ap = 0;//赚,陪数组下标
    int n;
    for (n = 1000; n <= 9999; n++) {
        int rn=reverse(n);
        if (rn == -1)continue;
        else if (rn - n > 800 && rn - n < 900) {
            a8[az++] = n;
        }
        else if (rn - n > -300 && rn - n < -200) {
            a2[ap++] = n;
        }
    }


    for(int i=0;a8[i]!=0;i++)
        for (int j = 0; a2[j] != 0; j++) {
            if (-a8[i] + reverse(a8[i]) - a2[j] + reverse(a2[j]) == 558)cout << a2[j]<<endl;
        }
    
    
    
    
    return 0;
}

9088

posted @ 2019-03-06 19:50  Kiss_the_rain  阅读(165)  评论(0编辑  收藏  举报