C++酱油笔记之猜字小魔术

#include<iostream>
#include<stdlib.h>
using namespace std;
 
int main()
{
    while(1)
    {
        unsignedchar ch[3]="",c;
        int j,sum = 0,t; //j为换行标志 ,t为产生的新汉字的操作数 
     
        cout << endl 
             <<" *************************************************************** " << endl
             <<" ****************    猜   字   小   魔   术    ***************** " << endl
             <<" *************************************************************** " << endl;
         
        ch[0] = 0XB0; //二进制为176,汉字起始
         
        for(int k=0;k<6;k++)
        {
            t = 0X1 << k; //将二进制0x1左移k位
            cout << endl << endl 
                 <<" *************************************************************** " << endl;
            j=0;
            for(int i=0;i<128;i++)
            {
                ch[1] = 0X80 | i; //按规律获得汉字第二个字节
                if(ch[1]&t)
                {
                    if(j%8==0)cout << endl;
                    cout << "   " << ch << "   ";
                    j++;
                }
            }
            cout << endl << endl 
                 <<" *************************************************************** "
                 << endl << endl;
            if(0 == k)
                cout << "  请记住其中的一个字,然后按Y或y " << endl << endl;
            else
                cout << "  请问你记住的字在这里吗?"<<endl
                     <<"  是请按Y或y,否则按N或n,游戏继续。"<< endl << endl;
               
            cout << "  请选择: " ;
            cin >> c ;
            if(c == 'Y' || c == 'y') {
                sum += 0x1 << k;
            }
            system("cls");
        }
        ch[1] = 0xc0 | sum;
        cout << endl
             <<" *************************************************************** " << endl << endl
             <<"                     你记住的字是:" << ch << endl <<endl
             <<" *************************************************************** " << endl << endl
             <<"  是否继续?(按Y或y继续) " << endl
             <<"  请选择: " ;
        cin >> c ;
        if( !(c == 'Y' || c == 'y'))return 0;
        system("cls");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值