Topic
Title: upside price tag
Mike's TV monopoly sample store other store shelves can be called: sample TV stores.
Its price is four digits (ie thousand dollars).
Li order price is clear, easy to use and a similar price tag digital prefabricated, as long as the color digital pen painted on it (see p1.jpg).
This price tag has a feature on some numbers, upside down is a reasonable number. Such as: 1,256,890 can. As a result, if the sign hanging down, it may have turned into another price, for example: 1958 is hanging upside down: 8561, the difference between a few thousand dollars ah !!
Of course, in most cases fail to read, for example, 1110 can not be reversed, because 0 can not start with a number.
One day, a tragedy has happened. A store clerk accidentally put a price tag to hang two down. Both price and brand TV sets sold out!
Fortunately, prices differ significantly, one of which lost more than 2 million price tags, price tags, but earned another eight hundred, together, but earn 558 yuan.
Based on this information, please calculate: money-losing price tag that the correct price should be how much?
The answer is an integer 4, please submit the numbers directly through the browser.
Note: Do not submit answers to the process, or other assistance in explaining the contents of the class.
answer
9088
Code
1 /*2013-蓝桥杯-省-A-4*/ 2 #include<iostream> 3 #include<map> 4 #include<vector> 5 #include<algorithm> 6 using namespace std; 7 map<char ,char> rev_map; 8 char num[7]={'1','2','5','6','8','9','0'}; 9 vector<int > g800p; 10 map<int , int > g800p_profmap; 11 vector<int > l200p; 12 map<int ,int > l200p_profmap; 13 struct val{ 14 char a[4]; 15 }; 16 17 void init(){ 18 rev_map['1']='1'; 19 rev_map['2']='5'; 20 rev_map['6']='9'; 21 rev_map['8']='8'; 22 rev_map['9']='6'; 23 rev_map['0']='0'; 24 } 25 int str2int(char a[]){ 26 int temp=0; 27 temp=a[0]-'0'+10*(a[1]-'0')+100*(a[2]-'0')+1000*(a[3]-'0'); 28 return temp; 29 } 30 void dfs(val cur,int pos){ 31 if(pos==4){ 32 if(cur.a[0]=='0'||cur.a[3]=='0'){ 33 return; 34 }else{ 35 char b[4]; 36 int bef_val=str2int(cur.a); 37 reverse_copy(cur.a,cur.a+4,b); 38 b[0]=rev_map[b[0]]; 39 b[1]=rev_map[b[1]]; 40 b[2]=rev_map[b[2]]; 41 b[3]=rev_map[b[3]]; 42 int aft_val=str2int(b); 43 int prof=aft_val-bef_val; 44 if(prof>800&&prof<900){ 45 //cout<<"find: (800) "<<bef_val<<endl; 46 //cout<<prof<<endl; 47 g800p.push_back(bef_val); 48 g800p_profmap[bef_val]=prof; 49 } 50 if(prof<-200&&prof>-300){ 51 //cout<<"find: (-200) "<<bef_val<<endl; 52 //cout<<prof<<endl; 53 l200p.push_back(bef_val); 54 l200p_profmap[bef_val]=prof; 55 } 56 57 return; 58 } 59 }else{ 60 for(int i=0;i<7;i++){ 61 cur.a[pos]=num[i]; 62 dfs(cur,pos+1); 63 } 64 } 65 } 66 int main(){ 67 init(); 68 val a; 69 dfs(a,0); 70 cout<<"dfs ok"<<endl; 71 for(vector<int>::iterator iter1=g800p.begin();iter1!=g800p.end();iter1++){ 72 for(vector<int>::iterator iter2=l200p.begin();iter2!=g800p.end();iter2++){ 73 if(g800p_profmap[*iter1]+l200p_profmap[*iter2]==558){ 74 cout<<*iter2<<" "<<endl; 75 break; 76 } 77 } 78 } 79 return 0; 80 } 81