
#include <reg52.h>桥友 // 引入敏搭槐单片机寄存器定义头文件// 数码管显示的密码模式,共16种,每种模式使用4位二进制表示unsigned char password[16] = {0x3F, // 0b00111111, 模式0
0x06, // 0b00000110, 模式1
0x5B, // 0b01011011, 模式2
0x4F, // 0b01001111, 模式3
0x66, // 0b01100110, 模式4
0x6D, // 0b01101101, 模式5
0x7D, // 0b01111101, 模式6
0x07, // 0b00000111, 模式7
0x7F, // 0b01111111, 模枝竖式8
0x6F, // 0b01101111, 模式9
0x77, // 0b01110111, 模式10
0x7C, // 0b01111100, 模式11
0x39, // 0b00111001, 模式12
0x5E, // 0b01011110, 模式13
0x79, // 0b01111001, 模式14
0x71 // 0b01110001, 模式15}void main() {unsigned char i = 0// 密码模式的索引
while (1) {// 读取四个开关的状态,每个开关对应一个二进制位
unsigned char switchValue = (P1 &0x0F) // 根据开关状态选择密码模式
i = switchValue // 设置数码管显示的密码模式
P0 = password[i] // 简单延时
for (unsigned int j = 0j <1000j++)
}
}
以上代码通过读取四个开关(连接到P1口的低4位)的状态来选择密码模式,并将选择的密码模式通过P0口设置到数码管上显示。
1.//存储结构:deque//多项式相加的基本过程:(1)、两个多项消丛式的最高次幂较高的那个,存入endPower;
// (2)、从ix=0开始,对多项式的对裂桥态应项做运算;
// (3)、递增,如果ix>=endPower,结束;否则,重复2和3。
#include <deque>
#include <iostream>
using namespace std
class Expression {
public:
Expression() { int highestPower=0factors=deque<double>(0.0)}
~Expression() { factors.clear()}
bool create()
void display()
Expression &add( Expression &another )
Expression &subtract( Expression &another )
int HighestPower() const
double Factor( int index ) const
private:
int highestPower//最高次幂
deque<double>factors//系数(从最高次幂~0的系数都保存,如果某次幂不存在,则肆源系数为0)
}
bool
Expression::
create() {
cout<<"Enter the highest power: "
cin>>highestPower
double dTemp
for( int ix=highestPowerix>=0--ix ) {
cout<<"Enter the factor of x^"<<ix<<" (double): "
cin>>dTemp
factors.push_front( dTemp )
}
return true
}
void
Expression::
display() {
for( int ix=highestPowerix>=0--ix ) {
if( ix<highestPower &&factors.at(ix)>0 )
cout<<"+"
if( factors.at(ix)!=0 ) {
cout<<factors.at(ix)
if( ix>0 )
cout<<"x"<<"^"<<ix
}
}
cout<<endl
}
Expression &
Expression::
add( Expression &another ) {
int endPower = (highestPower>another.HighestPower()) ? highestPower : another.HighestPower()
for( int ix=0ix<=endPower++ix ) {
if( ix>highestPower ) {
factors.push_back( another.Factor(ix) )
highestPower=ix
} else if( ix<=another.HighestPower() ){
factors.at(ix) += another.Factor(ix)
}
}
return *this
}
Expression &
Expression::
subtract( Expression &another ) {
int endPower = (highestPower>another.HighestPower()) ? highestPower : another.HighestPower()
for( int ix=0ix<=endPower++ix ) {
if( ix>highestPower ) {
factors.push_back( (-1)*another.Factor(ix) )
highestPower=ix
} else if( ix<=another.HighestPower() ){
factors.at(ix) -= another.Factor(ix)
}
}
return *this
}
int
Expression::
HighestPower() const {
return highestPower
}
double
Expression::
Factor( int index ) const {
return factors.at(index)
}
int main() {
Expression aExpression, bExpression
if( aExpression.create() )
aExpression.display()
if( bExpression.create() )
bExpression.display()
cout<<"aExpression.add( bExpression ): "<<endl
aExpression.add( bExpression )
aExpression.display()
cout<<"aExpression.subtract( bExpression ): "<<endl
aExpression.subtract( bExpression )
aExpression.display()
}
2.char *a
int m
cout<<"输入猴子个数:"<<endl
cin>>m
a=new char[m]
cout<<"输入N:"<<endl
int n
cin>>n
if(n>m)
{
cout<<"输入错误,必须小于M="<<m<<,重输入:"<<endl
cin>>n
}
for(int i=0i<mi++)
{
a[i]=1
}
bool c=true
for (int j=0j++)
{
for(int k=0k<mk++)
{
if(a[k]!=0)
{
c=false
break
}
else c=true
}
if(c!=true)//判断退出
break
if(j%n==0)
a[j%m]=0
}
int result=j%m
cout<<"最后猴子的序号是:"<<result<<endl
---------------2-----------------
insert(int arry[],int address,int data)
{
int l=arry.length()
for(int i=l-1i>addressi--)
{
arry[i]=arry[i-1]
}
arry[i]=data
}
sort01(int a[])
{
int temp
int l=a.length()
temp=a[0]
for(int i=1i<li++)
{
if(a[i]<temp)
insert(a,i-1,temp)
temp=a[i]
}
}
------------------------------------
swap(int *x,int *y)
{
int temp
temp=*x
*y=temp
*x=*y
}
l=a.length
temp1=a[0]temp2=a[1]
for(int k=0k<lk++)
for(int i=ki<li++)
{
if(a[i]>a[i+1])
swap(a[i],a[i+1)
}
3.//二叉树
struct node {
int key
node* left
node* right
}
//链表
struct list {
node* data
list* next
}
//队列
struct queue {
list* front
int count
list* rear
}
//Enqueue for Breadth-First Traversal
queue* BST::_enqueue (queue* Q, node* n) //进队
{
list* pNew = new list
pNew->data = n
pNew->next = NULL
if (Q->count == 0)
Q->front = pNew
else
Q->rear->next = pNew
Q->rear = pNew
Q->count++
return Q
}
//Dequeue for Breadth-First Traversal
node* BST::_dequeue (queue* &Q) //出队
{
if (Q->count == 1)
Q->rear = NULL
list* pDel = Q->front
node* temp = pDel->data
Q->front = Q->front->next
Q->count--
delete pDel
pDel = NULL
return temp
}
//Breadth-First Traversal (层序遍历)
void BST::_traverse (const node* T)
{
queue* Q = new queue
Q->front = Q->rear = NULL
Q->count = 0
while (T != NULL)
{
cout <<T->key <<" "
if (T->left != NULL)
Q = _enqueue (Q, T->left)//左孩子进队
if (T->right != NULL)
Q = _enqueue (Q, T->right)//右孩子进队
if (Q->count != 0) //排队输出下一个将要处理的节点
T = _dequeue (Q)
else //队列为空,跳出
T = NULL
}
return
}
你看看这个行不
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)