问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

一个3位数的数字转换小程序

发布网友 发布时间:2022-04-20 04:13

我来回答

3个回答

热心网友 时间:2023-09-11 10:59

合并版本的代码:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static char cha = 'o';
static char chb = 'x';
static char chc = 'U';
static char chd = 'D';

static char chx = 'o';
static char chy = 'x';

int isSSZ(int x, int y) // y在x的顺时针方向,距离*1到4
{
switch(x)
{
case '0': case '1': case '2':
case '3': case '4': case '5': return (y>=x&&y<=x+4)?1:0;
case '6': return (y=='7'||y=='8'||y=='9'||y=='0')?1:0;
case '7': return (y=='8'||y=='9'||y=='0'||y=='1')?1:0;
case '8': return (y=='9'||y=='0'||y=='1'||y=='2')?1:0;
case '9': return (y=='0'||y=='1'||y=='2'||y=='3')?1:0;
default : return 0;
}
}

void main(int argc, char* argv[])
{
if(argc<3)
{
printf("Error.\nno input file or output file.\n");
system("pause");
exit(-2);
}

FILE *fpi,*fpo;
char num[50];
char bin[][5] = { "000", "000", "000", "000", "000" };
char loop[][5] = { "000", "000", "000", "000", "000" };
char tmp[4] = { '\0', '\0', '\0', '\0' };
fpi=fopen(argv[1],"rt");
fpo=fopen(argv[2],"wt");
int count = 0, ixx = 0;
if(!fpi||!fpo)
{
printf("Error open input file or output file.");
system("pause");
exit(-1);
}
while(!feof(fpi))
{
if( fgets( num, 50, fpi ) != NULL)
{
count++;
if(count%30==1) fprintf(fpo,"num,bin01,bin02,bin03,bin04,bin05,loop1,loop2,loop3,loop4,loop5\n");
num[3]=loop[0][3]=loop[1][3]=loop[2][3]=loop[3][3]=loop[4][3]='\0';
num[3]=bin[0][3]=bin[1][3]=bin[2][3]=bin[3][3]=bin[4][3]='\0';

bin[0][0]=(num[0]=='0')?chx:((num[0]=='7')?chy:((num[0]=='1'||num[0]=='3'||num[0]=='5'||num[0]=='9')?'1':'2'));
bin[0][1]=(num[1]=='0')?chx:((num[1]=='7')?chy:((num[1]=='1'||num[1]=='3'||num[1]=='5'||num[1]=='9')?'1':'2'));
bin[0][2]=(num[2]=='0')?chx:((num[2]=='7')?chy:((num[2]=='1'||num[2]=='3'||num[2]=='5'||num[2]=='9')?'1':'2'));
bin[1][0]=(num[0]=='1')?chx:((num[0]=='8')?chy:((num[0]=='0'||num[0]=='3'||num[0]=='5'||num[0]=='9')?'1':'2'));
bin[1][1]=(num[1]=='1')?chx:((num[1]=='8')?chy:((num[1]=='0'||num[1]=='3'||num[1]=='5'||num[1]=='9')?'1':'2'));
bin[1][2]=(num[2]=='1')?chx:((num[2]=='8')?chy:((num[2]=='0'||num[2]=='3'||num[2]=='5'||num[2]=='9')?'1':'2'));
bin[2][0]=(num[0]=='2')?chx:((num[0]=='9')?chy:((num[0]=='0'||num[0]=='3'||num[0]=='5'||num[0]=='8')?'1':'2'));
bin[2][1]=(num[1]=='2')?chx:((num[1]=='9')?chy:((num[1]=='0'||num[1]=='3'||num[1]=='5'||num[1]=='8')?'1':'2'));
bin[2][2]=(num[2]=='2')?chx:((num[2]=='9')?chy:((num[2]=='0'||num[2]=='3'||num[2]=='5'||num[2]=='8')?'1':'2'));
bin[3][0]=(num[0]=='3')?chx:((num[0]=='4')?chy:((num[0]=='1'||num[0]=='2'||num[0]=='5'||num[0]=='8')?'1':'2'));
bin[3][1]=(num[1]=='3')?chx:((num[1]=='4')?chy:((num[1]=='1'||num[1]=='2'||num[1]=='5'||num[1]=='8')?'1':'2'));
bin[3][2]=(num[2]=='3')?chx:((num[2]=='4')?chy:((num[2]=='1'||num[2]=='2'||num[2]=='5'||num[2]=='8')?'1':'2'));
bin[4][0]=(num[0]=='5')?chx:((num[0]=='6')?chy:((num[0]=='1'||num[0]=='2'||num[0]=='3'||num[0]=='8')?'1':'2'));
bin[4][1]=(num[1]=='5')?chx:((num[1]=='6')?chy:((num[1]=='1'||num[1]=='2'||num[1]=='3'||num[1]=='8')?'1':'2'));
bin[4][2]=(num[2]=='5')?chx:((num[2]=='6')?chy:((num[2]=='1'||num[2]=='2'||num[2]=='3'||num[2]=='8')?'1':'2'));

fprintf( fpo, "%s", num );
fprintf( fpo, "," );
fprintf( fpo, "%s,%s,%s,%s,%s", bin[0], bin[1], bin[2], bin[3], bin[4] );
if(count==1)
{
fprintf( fpo, "\n" );
tmp[0]=num[0];tmp[1]=num[1];tmp[2]=num[2];
continue;
}

ixx=(num[0]-tmp[0])%10; ixx=(ixx>=0)?ixx:(10+ixx);
loop[0][0]=(ixx==0)?cha:((ixx==5)?chb:(isSSZ(num[0],tmp[0])?chc:chd));
loop[1][0]=(ixx==1)?cha:((ixx==6)?chb:(isSSZ(num[0],tmp[0])?chc:chd));
loop[2][0]=(ixx==2)?cha:((ixx==7)?chb:(isSSZ(num[0],tmp[0])?chc:chd));
loop[3][0]=(ixx==3)?cha:((ixx==8)?chb:(isSSZ(num[0],tmp[0])?chc:chd));
loop[4][0]=(ixx==4)?cha:((ixx==9)?chb:(isSSZ(num[0],tmp[0])?chc:chd));
ixx=(num[1]-tmp[1])%10; ixx=(ixx>=0)?ixx:(10+ixx);
loop[0][1]=(ixx==0)?cha:((ixx==5)?chb:(isSSZ(num[1],tmp[1])?chc:chd));
loop[1][1]=(ixx==1)?cha:((ixx==6)?chb:(isSSZ(num[1],tmp[1])?chc:chd));
loop[2][1]=(ixx==2)?cha:((ixx==7)?chb:(isSSZ(num[1],tmp[1])?chc:chd));
loop[3][1]=(ixx==3)?cha:((ixx==8)?chb:(isSSZ(num[1],tmp[1])?chc:chd));
loop[4][1]=(ixx==4)?cha:((ixx==9)?chb:(isSSZ(num[1],tmp[1])?chc:chd));
ixx=(num[2]-tmp[2])%10; ixx=(ixx>=0)?ixx:(10+ixx);
loop[0][2]=(ixx==0)?cha:((ixx==5)?chb:(isSSZ(num[2],tmp[2])?chc:chd));
loop[1][2]=(ixx==1)?cha:((ixx==6)?chb:(isSSZ(num[2],tmp[2])?chc:chd));
loop[2][2]=(ixx==2)?cha:((ixx==7)?chb:(isSSZ(num[2],tmp[2])?chc:chd));
loop[3][2]=(ixx==3)?cha:((ixx==8)?chb:(isSSZ(num[2],tmp[2])?chc:chd));
loop[4][2]=(ixx==4)?cha:((ixx==9)?chb:(isSSZ(num[2],tmp[2])?chc:chd));
fprintf( fpo, "," );
fprintf( fpo, "%s,%s,%s,%s,%s", loop[0], loop[1], loop[2], loop[3], loop[4] );
fprintf( fpo, "\n" );
tmp[0]=num[0];tmp[1]=num[1];tmp[2]=num[2];
} else
printf( "done. %d line(s) processed.\n", count);
}
fclose(fpi);
fclose(fpo);
system("pause");
}

热心网友 时间:2023-09-11 10:59

x,x+5 x-1,x-2,x-3,x-4 x+1,x+2,x+3,x+4 loop1

(注意loop1第一行没有,loop1中第二行生成的数据是通过080与596进行比较而形成的
方法为:X,X+5 因为080百位数0与596中百位数5比较刚好从|0-5|=5就用●表示
(如果两个位相等那就用○表示),在看十位,他们分别为8和9 是从9变到8也就等于x-1所以用↑表示,其他就这样的方法推出来。)

注意:百位和百位比较,个位与各位比较
不过他的方法是通过下一行与上一行进行比较来实现数字的转换的

热心网友 时间:2023-09-11 11:00

),在看十位,他们分别为8和9 是从9变到8也就等于x-1所以用↑表示,其他就这样的方法推出来。)

注意:百位和百位比较,个位与各位比较
不过他的方法是通过下一行与上一行进行比较来实现数字的转换的
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
做了好乱的梦,求解! ae缺少p1效果是要装什么插件? ...荣耀》中“网络诊断”居然可以测定酒店有无摄像头,这是好事吗? 七叶一枝花花苞里面的红米是什么 q了是什么意思? ...Q就可以,格式也没错,也只几十K,别人发给我都可以,哪里出问题了... 显的么说友Q在微 ?Q上新示怎让在说我空里动间的态不更好博 诺诗兰户外品牌怎么样 新隋唐英雄传张卫健萧妃是刘小庆吗 红尖椒和朝天椒介绍!红尖椒和朝天椒哪个辣? 如何建立一个纯数字的密码字典? 你好,我的苹果X型号是MQAC2QL/A,为什么用电信只... 怎样用VB 遍个小程序,实现数字与ASCII码之间的转换 iPhoneX MQAF2B/A支持电信么? 将一串数字转换为另一串数字或者掺杂着字母,有没... 苹果11pro型号号码MQAC2ZD/A是什么意思? 编程中怎么把输出的数字变成字母(名字) 得加什么... mqac2kh/a电信能用吗? 小程序字符串转换为数字如何实现 iPhoneX.mqac2b/a,是什么版本 光纤宽带与普通宽带的区别? 光纤宽带和一般宽带有什么不同? 光纤宽带有哪些种类? 光纤宽带是什么业务呢? 光纤宽带与普通宽带有什么不同? 光纤宽带和普通的有什么区别 江苏的失业补助金在哪领,在支付宝或者微信可以申... 江苏智慧人社失业登记原因填写错了怎么修改 光纤和宽带有什么区别? 失业保险待遇申领一直在审核中是怎么回事? mq-2的A,B脚有区别没? 帮用python做个小程序 JAVA写小程序 在键盘上输入一串字符串例如“huahua”... 苹果8plusMQ8D2ZA/A是什么版本的 苹果8plus型号mQ8E2ZA/A是真的吗 c语言小程序 最近在用C#编写一个小程序,比如,把string str=&#39;a... 苹果8P型号MQ982LL/A是什么意思?哪里产的? 小程序迁移名称设置规则是什么? 苹果8mq862/a是国行吗 微信小程序 传中文参给html页面,得到的是%EF%BB%... 微信小程序超级扫描枪扫出的条码是文本如何变成数值? C语言中十六进制字符数组转化为字符串 素质教育的具体内容是什么? 素质教育具体是什么?你怎么认为? 什么是素质教育 华为HUAWEI+FreeBuds+4无线耳机+可以用数据线充电吗 freebuds4充电器能通用吗 freebuds4充电头用多大 华为耳机freebuds+4充电用华为5A线可以充电吗