基础书上的一道题,也记下来吧。
给一个由整数组成的加密字符串,加密方法为:
原字符串中每一个整数与其前一位整数和后一位整数的和,如果其前一位或后一位不存在,则不需加其前一位或后一位.
例如:
若原字符串P为:01111001,则加密后的字符串Q为:12332111
即Q[1]=P[1]+P[2]=0+1=1
Q[2]=P[1]+P[2]+P[3]=0+1+1=2
Q[8]=P[7]+P[8]=0+1=1
现任一给你一个字符串P,求出二进制字符串Q并输出(既Q只能由0,1组成).若Q不存在则输出"NONE"
using System;
using System.Collections.Generic;
using System.Text;
namespace BinaryCode
{
class Program
{
static void Main(string[] args)
{
string Q = Console.ReadLine();
string[] Array=decode(Q);
Console.WriteLine("{0},{1}",Array[0],Array[1]);
Console.ReadKey();
}
public static string[] decode(string Q)
{
StringBuilder P = new StringBuilder();
P.Append('0', Q.Length);
bool[] IsTrue = new bool[2] { true, true };
string[] result = new string[2];
for (int j = 0; j <= 1; j++)
{
P[0] = (char)(j + 48);
for (int i = 0; i < Q.Length - 1; i++)
{
P[i + 1] = (char)(Q[i] - P[i] - (i == 0 ? 0 : P[i - 1]-48) + 48);
}
if (Q[Q.Length - 1] == (Q.Length == 1 ? P[Q.Length - 1] : (P[Q.Length - 1] + P[Q.Length - 2]-48)))
{
for (int i = 0; i < Q.Length; i++)
{
if (P[i] != '0' && P[i] != '1')
{
IsTrue[j] = false;
break;
}
}
}
else
{
IsTrue[j] = false;
}
Console.WriteLine(P.ToString());
result[j] = (IsTrue[j] == true) ? P.ToString() : "NONE";
}
return result;
}
}
}
运行结果:
分享到:
相关推荐
2021 - A Survey of Binary Code Similarity.pdf
2021_Semantic-aware Binary Code Representation with BERT PPT.pdf
翻译
reengineering methods using binary code disassembly
discovRE: Efficient Cross-Architecture Identification of Bugs in Binary Code是发表在NDSS'16会议上的论文。本文在SP'15的基础上提出了在效率和效果上都有提高的跨架构二进制代码漏洞检测方案。 Abstract & ...
Jointly Learning Binary Code for Large-scale Face Image Retrieval and Attributes Prediction
信息安全_数据安全_cwe_checker:Hunting Binary Code 安全可信 安全设计 数字取证 云安全 安全风险
Learning Binary Code for Personalized Fashion Recommendation
Binary Code Reranking Method Based on Bit Importance
According to the 2D binary code, phase plates are fabricated by etched glass or photoresist with different thicknesses corresponding to the code. It is introduced on the intermediate image plane to ...
binary tree 的C语言实现算法,需要在linux环境下编译
VB 2进制读取程序经典代码VB 2 classic binary code read program
Binary Code License Agreement for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6 SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION THAT...
Then, it is a multi-input data line, combinational logic circuit that converts the logic level "1" data at its inputs to an equivalent binary code at its output. Generally encoders produce outputs of...
开发 DApp 时要调用在区块链上的以太坊智能合约,就需要智能合约的 ABI。...ABI 也是程序间互动的接口,但程序是被编译后的 binary code。所以同样的接口,但传递的是 binary 格式的信息。所以 ABI
Decompile and debug binary code. Break down and analyze document files. Android Dalvik, Intel x86, ARM, MIPS, RISC-V, S7 PLC, Java, WebAssembly & Ethereum Decompilers. [Comment] Requirements: (Only ...
IT行业必须知道的东西,比如:access arm 磁头臂,存取臂C8 access time 存取时间go adder 加法器N address 地址bHYtD alphanumeric 字母... binary code 二进制码FoNl binary digit 二进制位,二进制数字i
("SUN") IS WILLING TO LICENSE THE SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS BINARY CODE LICENSE AGREEMENT AND SUPPLEMENTAL LICENSE ...
<span xss=removed>Code obfuscation is intended to thwart reverse engineering by making programmes hard to understand. Call <span xss=removed>chains collected by stack tracing can be used to ...
jre-8u202-macosx-x64.dmg适用于Mac OS X系统,是在Binary Code License (“BCL”)许可协议下提供最后的免费商业版本,允许用在生产环境中; 对于 2019 年 4 月 16 日开始的版本,Oracle JDK 许可协议已更改,也...