标题: 颠倒的价牌
小李的店里专卖其它店中下架的样品电视机,可称为:样品电视专卖店。
其标价都是4位数字(即千元不等)。
小李为了标价清晰、方便,使用了预制的类似数码管的标价签,只要用颜色笔涂数字就可以了(参见p1.jpg)。
这种价牌有个特点,对一些数字,倒过来看也是合理的数字。如:1 2 5 6 8 9 0 都可以。这样一来,如果牌子挂倒了,有可能完全变成了另一个价格,比如:1958 倒着挂就是:8561,差了几千元啊!!
当然,多数情况不能倒读,比如,1110 就不能倒过来,因为0不能作为开始数字。
有一天,悲剧终于发生了。某个店员不小心把店里的某两个价格牌给挂倒了。并且这两个价格牌的电视机都卖出去了!
庆幸的是价格出入不大,其中一个价牌赔了2百多,另一个价牌却赚了8百多,综合起来,反而多赚了558元。
请根据这些信息计算:赔钱的那个价牌正确的价格应该是多少?
# include<stdio.h>
int reverse(int n){
int store[4];
int result =0;
int r;
int i=0;
while(n!=0) //将一个数的各位存在数字中
{
r=n%10;
n/=10;
store[i]=r;
i++;
}
for(int k=0;k<i;k++ )
{
if(store[k]==3||store[k]==4||store[k]==7)
return 0;
else if(store[k]==6) //数字中有6变9
store[k]=9;
else if(store[k]==9)//数字中有9变6
store[k]=6;
}
for(int j=0;j<i;j++)//计算翻转后数的大小
{
if(store[0]==0)
return 0;
if(j==0)
result =store[j];
else
result =result*10+store[j];
}
return result;
}
int main()
{
int sub=0;
int sub2=0;
for(int i=1000;i<=9999;i++)//遍历所有四位数
{
if(reverse(i)==0)
continue;
sub =i-reverse(i); //赔的钱
if(sub<200||sub>=300)
continue;
for(int j=1000;j<=9999;j++)//遍历所有四位数
{
if(reverse(j)==0)
continue;
sub2 =reverse(j)-j; //赔的钱
if(sub2<800||sub2>=900)
continue;
if(sub2-sub==558)
{
printf("赔钱的价格为 %d ",i) ;
printf("赚钱的价格为 %d\n",j);
}
}
}
}
赔钱的价格为 9088 赚钱的价格为 1061
赔钱的价格为 9088 赚钱的价格为 2062
赔钱的价格为 9088 赚钱的价格为 5065
赔钱的价格为 9088 赚钱的价格为 6069
赔钱的价格为 9088 赚钱的价格为 8068
赔钱的价格为 9088 赚钱的价格为 9066
--------------------------------
Process exited with return value 0
Press any key to continue . . .