enum class E
{};
int main()
{
E e1{ 0 }; // ok
E e2 = 0; // not ok
// error : cannot initialize a variable of
// type 'E' with an rvalue of type 'int'
}
Run Code Online (Sandbox Code Playgroud)
我的编译器clang 4.0有选项-std=c++1z.
预计E e2 = 0;不行,因为E是强类型的.然而,让我感到惊讶的是E e1{ 0 };应该没问题.
为什么强类型枚举可以用一个整数来初始化static_cast?
我在我的android项目中使用AES GCM身份验证,它工作正常.但与openssl API生成标记相比,在验证标记时遇到一些问题.请在下面找到java代码:
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
byte[] iv = generateRandomIV();
IvParameterSpec ivspec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
int outputLength = cipher.getOutputSize(data.length); // Prepare output buffer
byte[] output = new byte[outputLength];
int outputOffset = cipher.update(data, 0, data.length, output, 0);// Produce cipher text
outputOffset += cipher.doFinal(output, outputOffset);
Run Code Online (Sandbox Code Playgroud)
我在iOS中使用openssl,并使用下面的代码生成身份验证标记
NSMutableData* tag = [NSMutableData dataWithLength:tagSize];
EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, [tag length], [tag mutableBytes])
Run Code Online (Sandbox Code Playgroud)
在java或bouncy castle中,无法获得openssl返回的确切身份验证标记,并且可以帮助我解决此问题.谢谢
给出以下代码.
int[] eg = {21,20,1,12,2}
public numbers(int[] eg)
{
for(int i=0; i < eg.length; i++)
Run Code Online (Sandbox Code Playgroud)
我希望eg.length是5,其中eg[0]= 21 eg[1]= 20, eg[3]将= 1
我想检查例如[i]的每个元素,看看它是1位数还是2位数,我试着eg[0].length无济于事,但我是否正确假设它只适用于数组列表?
我的要求如下:
输入:一个整数数组(值将仅为0/1)和整数ζ
进程:检测无效零的所有索引
一个无效零是属于0的运行,其长度大于或等于ζ零
输出:ArrayList包含无效零的所有索引
例:
input: Data: 1,0,0,0,1,1,1,1,1,0,1,0,1,0,1,1,0,0,1,1,1,1
? : 2
output: 2,3,4,17,18
Run Code Online (Sandbox Code Playgroud)
============================================
我使用以下算法,想知道是否有更好的方法吗?
算法:验证(A [1 ... n],ζ)
Counter ? 0
For i ? 1 to n do
if A[i] == 0 then
counter ? counter +1
if i == n and counter >= ? then
for j ? (n-counter) to n do
R.add(j)
else
if counter >= ?
for j ? (i-counter-1) to (i-1) do
R.add(j)
counter ? 0
return R
Run Code Online (Sandbox Code Playgroud)
谢谢
例子:
String t;
String j ="j2se";
Scanner sc =new Scanner(System.in);
System.out.println("enter the search key:");
t=sc.next();
if (j.contains(t))
{
System.out.println("yes");
}
else System.out.println("no");
Run Code Online (Sandbox Code Playgroud)
如果用户输入“j2”、“se”或“j2s”作为输入,则输出为“是”。如果输入为“jse”,则输出为“no”。
是否有一种方法可以忽略字符串搜索中存储的数字,例如忽略大写或小写字母?
是否有更短的方法从其他列表创建子列表?例如:我有一个Contactobiect,这个obiect包含的String字段adres
public List<String> getAdreses(long personID) {
List<String> adreses=null;
for(Contact mail : getContacts(personID)){
adreses.add(mail.getMail());
}
return adreses;
}
Run Code Online (Sandbox Code Playgroud)