=================程序开始=================
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std
//0的ASCII码
#define NUM_START 48
//输入数字的最大位数
#define MAX_NUM 20
//最大行数
#define MAX_LINE 8
//输出的所有字符数
#define ALL_SYMBO 12
//最大行数
#define MAX_ROW 8
//每行显示的最大LED字数
#define MAX_LROW 9
//最大 *** 作数
#define MAX_OPT 100
// *** 作符个数
#define ALL_OPTS 6
/* *** 作符*/
#define OPTS_POS ALL_OPTS + 3
#define SOPTS_POS ALL_OPTS + 2
#define NOPTS_POS ALL_OPTS + 1
#define OPT_ADD 0
#define OPT_REDUCE 1
#define OPT_MULTIP 2
#define OPT_DIVISION 3
char Opts[ALL_OPTS]={'+','-','*','/','(',')'}
/*译码表*/
int Code[ALL_SYMBO+1][MAX_LINE]=
{
{1,1,1,1,1,1,0}, //0
{0,0,1,1,0,0,0}, //1
{0,1,1,0,1,1,1}, //2
{0,1,1,1,1,0,1}, //3
{1,0,1,0,0,1,1}, //4
{1,1,0,1,1,0,1}, //5
{1,1,0,1,1,1,1}, //6
{0,1,1,1,0,0,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,1,0,1}, //9
{0,0,0,0,0,0,0}, //.
{0,0,0,0,0,0,1}, //-
}
/*计算*/
float Calc()
void OptCalc(int _opt)
/*标准化*/
int Fliter(char *_input,int _size)
/*字符串转化为数字*/
float Char2Num(char *_c,int _size)
/*数字转换成字符串*/
char* Num2Char(int _int)
char* Num2Char(float _flt,int prc = 3)
/*字符串转化为编码*/
int Char2Code(char *_c,int size,int *code)
/*输入并打印LED数字*/
void PrintLEDNum(int _show)
void PrintLEDNum(float _show)
/*打印LED数字*/
void Print(int _rg,int *_cd,int _r=0)
/* *** 作数和每种 *** 作数的个数*/
int opts[ALL_OPTS + 4]
char opt[MAX_OPT][MAX_NUM]
void main()
{
float a=0.0
cin>>a
PrintLEDNum(a)
return
}
float Calc()
{
float res=0.0f
OptCalc(OPT_MULTIP)
OptCalc(OPT_DIVISION)
OptCalc(OPT_ADD)
OptCalc(OPT_REDUCE)
return Char2Num(opt[0],strlen(opt[0]))
}
void OptCalc(int _opt)
{
for(int i=0i<opts[_opt]i++)
{
for(int j=0j<opts[OPTS_POS]j++)
{
if(opt[j][0]==Opts[_opt])
{
float left = Char2Num(opt[j-1],strlen(opt[j-1]))
float right = Char2Num(opt[j+1],strlen(opt[j+1]))
float t=0
switch(_opt)
{
case OPT_ADD:
t=left+right
break
case OPT_REDUCE:
t=left-right
break
case OPT_MULTIP:
t=left*right
break
case OPT_DIVISION:
t=left/right
break
}
strcpy(opt[j-1],Num2Char(t))
for(int k=j-1k<opts[OPTS_POS]-1k+=2)
{
strcpy(opt[k+1],opt[k+3])
strcpy(opt[k+2],opt[k+4])
}
for(int k=0k<MAX_NUMk++)
{
opt[opts[OPTS_POS]][k]='\0'
opt[opts[OPTS_POS]-1][k]='\0'
}
opts[SOPTS_POS]-=1
opts[NOPTS_POS]-=1
opts[OPTS_POS]-=2
//opts[_opt]--
break
}
}
}
return
}
int Fliter(char *_input,int _size)
{
int res=0
for(int i=0i<MAX_OPTi++)
{
for(int j=0j<MAX_NUMj++)
{
opt[i][j]='\0'
}
}
for(int i=0i<_sizei++) //删除空格
{
if(_input[i]==' ')
{
for(int j=ij<_size-1j++)
{
_input[j]=_input[j+1]
}
_size-=1
}
for(int j=0j<ALL_OPTSj++)
{
if(_input[i]==Opts[j])
{
opts[j]++
res++
}
}
}
if(opts!=0)
{
int l=0
int iOldOpt = -1
int curOpt = 0
for(int i=0i<_sizei++)
{
for(int j=0j<ALL_OPTSj++)
{
if(_input[i]==Opts[j])
{
curOpt++
for(int k=iOldOpt+1k<ik++)
{
opt[l][k-iOldOpt-1] = _input[k]
}
l++
iOldOpt = i
opt[l][0] = _input[i]
l++
opts[OPTS_POS]++
opts[SOPTS_POS]++
if(i!=0)
{
opts[OPTS_POS]++
}
if(curOpt==res)
{
for(int k=i+1k<_sizek++)
{
opt[l][k-iOldOpt-1] = _input[k]
}
l++
opts[OPTS_POS]++
}
}
}
}
}
else
{
strcpy(opt[0],_input)
}
opts[NOPTS_POS]=opts[OPTS_POS]-opts[SOPTS_POS]
return res
}
float Char2Num(char *_c,int _size)
{
char tc[MAX_NUM]
for(int i=0i<MAX_NUMi++)
{
tc[i]='\0'
}
float res = 0.0f
int point = 0
int pob = 0 //正负判断
if(_c[0]=='-')
{
pob = -1
_c++
strcpy(tc,_c)
}
else
{
strcpy(tc,_c)
}
for(int i=0i<_sizei++)
{
if(tc[i]=='.')
{
point = i
break
}
}
if(point!=0)
{
for(int i=0i<pointi++)
{
int itp=tc[i]-NUM_START
res+=itp*pow((double)10,point-i-1)
}
for(int i= point+1i<_sizei++)
{
int itp=tc[i]-NUM_START
res+=itp*pow((double)10,point-i)
}
}
else
{
for(int i= 0i<_sizei++)
{
int itp=tc[i]-NUM_START
res+=itp*pow((double)10,_size-i-1)
}
}
if(pob==-1)
{
return -1*res
}
else
{
return res
}
}
char* Num2Char(int _int)
{
char res[MAX_NUM-1]
bool notzero=false
for(int i=0i<MAX_NUM-1i++)
{
res[i]='\0'
}
if(_int ==0)
{
res[0]='0'
}
if(_int>0)
{
int j=0
for(int i=MAX_NUM-2i>=0i--)
{
int t=_int/pow((double)10,i)
if((int)(_int/pow((double)10,i))!=0)
{
notzero=true
}
if(notzero)
{
int t=_int/pow((double)10,i)
res[j] = (int)(_int/pow((double)10,i)) + NUM_START
_int -= (int)(_int/pow((double)10,i))*pow((double)10,i)
j++
}
}
}
else if(_int <0)
{
_int=abs(_int)
int j=1
for(int i=MAX_NUM-2i>=0i--)
{
int t=_int/pow((double)10,i)
if((int)(_int/pow((double)10,i))!=0)
{
notzero=true
}
if(notzero)
{
int t=_int/pow((double)10,i)
res[j] = (int)(_int/pow((double)10,i)) + NUM_START
_int -= (int)(_int/pow((double)10,i))*pow((double)10,i)
j++
}
}
res[0]='-'
}
return res
}
char* Num2Char(float _flt,int prc)
{
char *res=new char[MAX_NUM]
bool mdi = false//如果该数在1与-1之间
for(int i=0i<MAX_NUMi++)
{
res[i]='\0'
}
if(_flt<1.0&&_flt>-1.0)
{
mdi = true
}
_flt*=pow((double)10,prc)
int toint=(int)_flt
strcpy(res,Num2Char(toint))
int j=0
for(int i=strlen(res)-1i>=0i--)
{
res[i+1]=res[i]
j++
if(j==prc)
{
res[i]='.'
break
}
}
j=0
if(mdi==true)
{
for(int i=strlen(res)-1i>=0i--)
{
res[i+1]=res[i]
j++
if(j==prc+1)
{
res[i]='0'
break
}
}
}
return res
}
void PrintLEDNum(int _show)
{
char prt[MAX_NUM]
int code[MAX_NUM]
strcpy(prt,Num2Char(_show))
int rang = strlen(prt)
Char2Code(prt,rang,code)
int row=rang/MAX_LROW
int i=0
for(i=0i<rowi++)
{
Print(MAX_LROW,code,i)
cout<<endl
}
if(rang%MAX_LROW!=0)
{
Print(rang%MAX_LROW,code,row)
cout<<endl
}
//Print(rang%MAX_LROW,code,i*MAX_LROW)
/*
for(int j=0j<rangj++)
{
int a=Code[code[j]][1]
if(Code[code[j]][1])
{
cout<<setw(8)<<"-- "
}
else
{
cout<<setw(8)<<" "
}
}
cout<<endl
for(int i=0i<2i++)
{
for(int j=0j<rangj++)
{
if(Code[code[j]][0])
{
cout<<setw(4)<<"| "
}
else
{
cout<<setw(4)<<" "
}
if(Code[code[j]][2])
{
cout<<setw(4)<<"| "
}
else
{
cout<<setw(4)<<" "
}
}
cout<<endl
}
for(int j=0j<rangj++)
{
if(Code[code[j]][6])
{
cout<<setw(8)<<"-- "
}
else
{
cout<<setw(8)<<" "
}
}
cout<<endl
for(int i=0i<2i++)
{
for(int j=0j<rangj++)
{
if(Code[code[j]][5])
{
cout<<setw(4)<<"| "
}
else
{
cout<<setw(4)<<" "
}
if(Code[code[j]][3])
{
cout<<setw(4)<<"| "
}
else
{
cout<<setw(4)<<" "
}
}
cout<<endl
}
for(int j=0j<rangj++)
{
if(Code[code[j]][4])
{
cout<<setw(8)<<"-- "
}
else
{
cout<<setw(8)<<" "
}
}
cout<<endl
*/
}
void PrintLEDNum(float _show)
{
char prt[MAX_NUM]
int code[MAX_NUM]
strcpy(prt,Num2Char(_show))
int rang = strlen(prt)
Char2Code(prt,rang,code)
int row=rang/MAX_LROW
int i=0
for(i=0i<rowi++)
{
Print(MAX_LROW,code,i)
cout<<endl
}
if(rang%MAX_LROW!=0)
{
Print(rang%MAX_LROW,code,row)
cout<<endl
}
}
int Char2Code(char *_c,int size,int *code)
{
int len=0
for(int i=0i<MAX_NUMi++)
{
code[i]=-1
}
for(int i=0i<sizei++)
{
if(_c[i]>=NUM_START &&_c[i]<NUM_START+10)
{
code[i]=_c[i]-NUM_START
}
else if(_c[i]=='.')
{
code[i]=10
}
else if(_c[i]=='-')
{
code[i]=11
}
}
return 1
}
void Print(int _rg,int *_cd,int _r)
{
int dist=8
for(int j=0j<_rgj++)
{
if(Code[_cd[j+MAX_LROW*_r]][1])
{
cout<<setw(dist)<<"-- "
}
else
{
cout<<setw(dist)<<" "
}
}
cout<<endl
for(int i=0i<2i++)
{
for(int j=0j<_rgj++)
{
if(Code[_cd[j+MAX_LROW*_r]][0])
{
cout<<setw(dist/2)<<"| "
}
else
{
cout<<setw(dist/2)<<" "
}
if(Code[_cd[j+MAX_LROW*_r]][2])
{
cout<<setw(4)<<"| "
}
else
{
cout<<setw(4)<<" "
}
}
cout<<endl
}
for(int j=0j<_rgj++)
{
if(Code[_cd[j+MAX_LROW*_r]][6])
{
cout<<setw(dist)<<"-- "
}
else
{
cout<<setw(dist)<<" "
}
}
cout<<endl
for(int i=0i<2i++)
{
for(int j=0j<_rgj++)
{
if(Code[_cd[j+MAX_LROW*_r]][5])
{
cout<<setw(dist/2)<<"| "
}
else
{
cout<<setw(dist/2)<<" "
}
if(Code[_cd[j+MAX_LROW*_r]][3])
{
cout<<setw(dist/2)<<"| "
}
else
{
cout<<setw(dist/2)<<" "
}
}
cout<<endl
}
for(int j=0j<_rgj++)
{
if(_cd[j+MAX_LROW*_r]==10)
{
cout.setf (ios::left)
cout<<setw(dist)<<"。"
cout.setf (ios::right)
}
else if(Code[_cd[j+MAX_LROW*_r]][4])
{
cout<<setw(dist)<<"-- "
}
else
{
cout<<setw(dist)<<" "
}
}
cout<<endl
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)