[C++] 纯文本查看 复制代码
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char RegKey[200];
int tip[21] = {80, 108, 101, 97, 115, 101, 0, 105, 110, 112, 117, 116, 0,
82, 101, 103, 75, 101, 121, 58, 0};
// Please input RegKey:
int ok[32] = {86, 101, 114, 121, 0, 103, 111, 111, 100, 33, 0, 89, 111, 117, 114, 0,
82, 101, 103, 75, 101, 121, 0, 105, 115, 0, 82, 105, 103, 104, 116, 33};
// Very good! Your RegKey is Right!
int no[28] = {83, 111, 114, 114, 121, 33, 0, 89, 111, 117, 114, 0,
82, 101, 103, 75, 101, 121, 0, 105, 115, 0, 87, 114, 111, 110, 103, 33};
// Sorry! Your RegKey is Wrong!
int TestLen[25] = {82, 101, 103, 75, 101, 121, 0, 108, 101, 110, 103, 116, 104, 0,
109, 117, 115, 116, 0, 98, 101, 0, 49, 56, 46};
// RegKey length must be 18.
for(int i = 0; i < 21; i++)
cout << (char)tip[i];
cin >> RegKey;
int key1 = 32, key2, key3, key4, key5 = 16, key6, key7, key8, key9;
// 判断输入位数是否为 18 若不等于 18 输出提示
if(strlen(RegKey) != 18)
{
for(int i = 0; i < 25; i++)
cout << (char)TestLen[i];
cout << endl;
}
else
{
/*
————————————————
| 32 | xx | xx |
| | | |
| xx | 16 | xx |
| | | |
| xx | xx | xx |
————————————————
*/
// 判断左上角是否为 32 且中心是否为 16
if((RegKey[0] - '0') * 10 + (RegKey[1] - '0') == key1
&& (RegKey[8] - '0') * 10 + (RegKey[9] - '0') == key5)
{
key2 = (RegKey[2] - '0') * 10 + (RegKey[3] - '0');
key3 = (RegKey[4] - '0') * 10 + (RegKey[5] - '0');
key4 = (RegKey[6] - '0') * 10 + (RegKey[7] - '0');
key6 = (RegKey[10] - '0') * 10 + (RegKey[11] - '0');
key7 = (RegKey[12] - '0') * 10 + (RegKey[13] - '0');
key8 = (RegKey[14] - '0') * 10 + (RegKey[15] - '0');
key9 = (RegKey[16] - '0') * 10 + (RegKey[17] - '0');
// 这里判断一下右下角是否为 0 因为右下角为 0 则除了已给出的 32 和 16
// 其他部位全部填 0 则可正确注册
if(key9 != 0)
{
// 判断横排三组数相乘是否相等
if(key1 * key2 * key3 == key4 * key5 * key6
&& key4 * key5 * key6 == key7 * key8 * key9)
{
// 判断竖排三组数相乘是否相等
if(key1 * key4 * key7 == key2 * key5 * key8
&& key2 * key5 * key8 == key3 * key6 * key9)
{
// 判断对角两组数相乘是否相等
if(key1 * key5 * key9 == key3 * key5 * key7)
{
for(int i = 0; i < 32; i++)
cout << (char)ok[i];
cout << endl;
}
else
{
for(int i = 0; i < 28; i++)
cout << (char)no[i];
cout << endl;
}
}
else
{
for(int i = 0; i < 28; i++)
cout << (char)no[i];
cout << endl;
}
}
else
{
for(int i = 0; i < 28; i++)
cout << (char)no[i];
cout << endl;
}
}
else
{
for(int i = 0; i < 28; i++)
cout << (char)no[i];
cout << endl;
}
}
else
{
for(int i = 0; i < 28; i++)
cout << (char)no[i];
cout << endl;
}
}
return 0;
}