小编tem*_*def的帖子

加密哈希函数的时间复杂度是多少?

比如说 MD5 或 SHA-1?这两者的时间复杂度是多少?我试图在互联网上找到它,但它非常有限,我得到的只是它们都是 O(n)。谁能进一步启发我?也许给我一个最坏的情况和最好的情况?

security big-o time-complexity cryptographic-hash-function

0
推荐指数
1
解决办法
2267
查看次数

Java 中的私有变量和 C++ 结构中的私有变量有什么区别?

Java 类中的私有变量和 C++ 结构中的私有变量有什么区别?

Java 代码示例见下文:实现 ADT 表。C++ 示例见下文:应用“隐藏实现”

我在网上找不到任何与此特定主题相关的有用资源

Java示例:

class Table{
    private int size;
    private int num;//numbers of items are stored in the arrray
    private int[] array;

    public Table(int size, int[] array){
        this.size = size;
        this.array = new int[size];
    }

    public insert(int[] array, int newItem){
        if(num<size){
            //for loop for adding items into the array;
        }
        else if(num>=size){
            //increment the size and copy the original array to the new array
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

C++实现隐藏示例:

struct B{
private:
    char j; …
Run Code Online (Sandbox Code Playgroud)

c++ java variables struct class

0
推荐指数
1
解决办法
244
查看次数

查找字符串是否包含字符串向量的任何一个元素的最佳方法

我有一个目标字符串和一个字符串向量。我想检查向量中的任何字符串是否包含在我的目标字符串中并执行某些操作。否则,做别人。

这样做的最佳方法是什么。我知道我可以使用 for 循环和 string::find。但是如果stl中还有其他功能可以做到这一点吗?还是使用 lambda 函数?

我试过 for 循环,它肯定会工作

std::string target = "United States"; 

std::vector<std::string> stringVec = {"United","America","Kindom"};

For (auto it = stringVec.cbegin(); it!=stringVec.cend(); ++it)
{

    if (target.find(*it)!=std::string::npos)
        cout << "Contains";
    else
        cout << "Not existed";
}
Run Code Online (Sandbox Code Playgroud)

c++ string algorithm search

0
推荐指数
1
解决办法
476
查看次数

是什么导致此“存储空间不足的地址”错误?

    struct ListNode {
        int val;
        struct ListNode *next;
    };


   struct ListNode* test = malloc(sizeof(struct ListNode*));

   test->val = 6;

   struct ListNode* lex = malloc(sizeof(struct ListNode*));

   test->next = lex;

   return test;
Run Code Online (Sandbox Code Playgroud)

此时我应该收到一个填充的结构。相反,我得到了这个:

   Line 14: Char 18: runtime                                                    
   error: store to address   
   0x602000000118 with      
   insufficient space for an 
   object of type 'struct ListNode 
   *' (solution.c)


   0x602000000118: note: pointer   
   points here

   be be be be  00 00 00 00 00 00 
   00 00  02 00 00 00 ff ff ff 02  
   08 00 00 …
Run Code Online (Sandbox Code Playgroud)

c malloc pointers sizeof

0
推荐指数
1
解决办法
1260
查看次数

程序仅适用于 .h 文件中的 {} 符号

我有三个文件。为什么程序仅适用于 .h 文件中的 {} 符号?

szereg.c:

    #include "szereg.h"

double szereg(double x, double eps, int *sw, int *M, int *stop){ 

    double s, w;
    int i = 2;
        s=x;
        w=x;
    do{ 
        if(*sw==*M){
            if(fabs(w)<=eps && *sw==*M)
                *stop =3;
            else
                *stop = 1;
            return s;
        }
        w=((-w*x)/i)*(i-1);
        s=s+w;
        *sw+=1;
        i++;
    } 
    while (fabs(w) >= eps); 

    *stop = 2;

    return s; 
}
Run Code Online (Sandbox Code Playgroud)

szereg.h:

    double szereg(){};
Run Code Online (Sandbox Code Playgroud)

主文件:

        #include <stdio.h>
        #include <math.h>
        #include <stdlib.h>
        #include "szereg.h"

        FILE *fw; 
        extern double szereg(); 

        int main(){ 

            int lp, sw=1, M, …
Run Code Online (Sandbox Code Playgroud)

c split header-files code-splitting

0
推荐指数
1
解决办法
45
查看次数

为什么 Collections.sort 没有将这些字符串按正确的顺序排列?

我是 Java 的初学者。我不明白为什么这段代码不能正常工作。我糊涂了。有人可以解释为什么。这是我的代码:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class HW20 {

    public static ArrayList<String> abc(String ... strings) {

        ArrayList<String> strings1 = new ArrayList<>(Arrays.asList(strings));
        Collections.sort(strings1);
        return strings1;
    }

    public static void main(String[] args) {

        ArrayList<String> strings1 = abc("1", "9", "4", " 2", "6", "8", "3", "5", "7", "0");
        System.out.println(strings1);
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

[ 2, 0, 1, 3, 4, 5, 6, 7, 8, 9]
Run Code Online (Sandbox Code Playgroud)

谢谢!

java sorting collections

0
推荐指数
1
解决办法
79
查看次数

python 中 sin(45) 和 cos(45) 的不同值,尽管它们是等效的

我正在制作一个计算对象移动距离的程序,但是当我使用 45 作为角度(sin45 和 cos45 等效)运行程序时,垂直高度和水平高度的输出不同

import math

angle = float(input("Enter Angle of Movement(In Degrees): "))
print("Angle is: ",angle,"°")

horizontal_distance = (abs(overall_distance*math.sin(90-angle)))
print("Horizontal Distance:",horizontal_distance,"m")

vertical_distance = (abs(overall_distance*math.cos(90-angle)))
print("Vertical Distance:",vertical_distance,"m")
Run Code Online (Sandbox Code Playgroud)

python math trigonometry

0
推荐指数
1
解决办法
368
查看次数

Can a virtual function be a friend of another class?

Everywhere in theory, it is written that "A virtual function can be declared as a friend of another class", but practically on implementing it, the compiler throws an error saying "virtual functions cannot be friends".

Here is a C++ program to illustrate this:

#include <iostream>
using namespace std;

class extra;
class base {
public:
    virtual friend  void print(extra e);

    void show()
    {
        cout << "show base class" << endl;
    }
};

class derived : public base {
public:
    void …
Run Code Online (Sandbox Code Playgroud)

c++ virtual friend

0
推荐指数
1
解决办法
364
查看次数

运行时间为 O(n^2 log n) 的算法示例?

我必须构造一个算法,其上限为 O(n 2 log n)。谁能提供有关 O(n 2 log n) 算法的示例吗?我似乎无法全神贯注于它。

我对它的想象是两个嵌套的 for 循环,在第二个循环中执行 log n 操作。它是否正确?

algorithm big-o

0
推荐指数
1
解决办法
2136
查看次数

如何在二进制搜索中找到数组的最后一个元素

在二进制搜索算法中,上限元素是array.length-1,那我怎样才能找到数组的最后一个元素?

如果长度为8的数组的元素的下限和上限分别为6和7,那么我的mid元素将显示为:

mid =(6 + 7)/ 2,即java中的6

java algorithm binary-search

-1
推荐指数
1
解决办法
5973
查看次数