#include <stdio.h>
#include <string.h>
int main() {
char a[100], b[100];
char *ret;
scanf("%[^\n]s", a);
scanf("%[^\n]s", b);
ret = strstr(a, b);
if (ret != NULL)
printf("its a substring");
else
printf("not a substring");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的目的是检查字符串中父字符串中是否存在子字符串.我strstr()
从这里了解了这个功能.
我以前%[^\n]s
在我的代码中使用过它们并且运行良好.但是,在这种情况下,只要在键入一个字符串后按返回/输入,输出就是not a substring
.
我做错了什么?
我正在尝试使用 POST 请求访问在 AWS EC2 实例的端口 8080 上运行的服务器。
这是当我发送请求时 POSTMAN 给我的响应:
错误:主机名/IP 与证书的替代名称不匹配:主机:some-address.compute.amazonaws.com。不在证书的替代名称中:DNS:chat.my-app.app
我尝试寻找它,但这似乎是 NodeJS 和证书问题。
我没有使用 Node,我不知道如何处理证书?(我不太了解我需要它们的方式或原因),但我有 .pem 文件,它帮助我通过 SSH 连接到 EC2 实例。
如何解决 Postman 中的此错误?
此外,如果重要的话,它是一个 Graphql 请求。
我正在尝试运行一个 docker 实例并不断遇到该服务器。这是我尝试设置实例后得到的结果:
Starting instance ... done
Attaching to instance
instance | {"t":{"$date":"2020-12-08T14:06:42.033Z"},"s":"F", "c":"CONTROL", "id":20574, "ctx":"main","msg":"Error during global initialization","attr":{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to open /var/log/mongodb/mongod.log"}}}
instance exited with code 1
Run Code Online (Sandbox Code Playgroud)
文件权限为:
$ ls -l /var/log/mongodb/mongod.log
-rwxr-xr-x 1 mongodb mongodb 0 Dec 8 19:32 /var/log/mongodb/mongod.log
Run Code Online (Sandbox Code Playgroud)
我还尝试过什么:
mongodb
作为所有者和组添加到 lib 和 log mongodb 文件夹。我不确定这个问题是从哪里来的。希望对此有一些替代解决方案。
我试图在彩虹笔画画布上工作,但每当我画画时,线条都会出现点缀.只有当我移动得非常慢时才能正常显示.
'mousemove'事件监听器,实际上无法检测到快速更改,或者我的代码中是否存在其他问题?此外,这里是codepen链接,如果有人想要一个工作程序.
const canvas = document.querySelector('#draw');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx = canvas.getContext("2d");
ctx.lineWidth = 50;
ctx.lineCap = "round";
ctx.lineJoin = "line";
ctx.strokeStyle = 0;
let hue = 0;
var [x, y] = [0, 0];
let paint = false;
canvas.addEventListener('mousedown', beginDraw);
function beginDraw(e) {
paint = true;
[x, y] = [e.x, e.y];
// ctx.moveTo(x, y);
}
canvas.addEventListener('mousemove', draw);
function draw(e) {
if (paint == false)
return;
ctx.strokeStyle = `hsla(${hue}, 100%, 50%, 0.5)`;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(e.x, …
Run Code Online (Sandbox Code Playgroud) 我正在阅读 Kenneth Reek 的“Pointers on C”,并看到了这一行:
结构变量是标量,因此您可以使用它执行与其他标量相同类型的操作。
那么它是什么意思呢?
我在 SO 上发现了一个类似的问题,但它与其他语言有关(我猜是 SQL)
谢谢你。
我正在做K&R C的问题2.1,它基本上要我们搞乱并理解标题库
#include<stdio.h>
#include<limits.h>
#include<float.h>
int main()
{
printf("%lu", ULONG_MAX);
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个程序时,我得到了输出
4294967295
Run Code Online (Sandbox Code Playgroud)
等于2 32 -1.我期待这个值(因为K&R在它的附录中具有相同的值).
现在我改%lu
到%llu
.
由于我对C语言知之甚少,我认为这%llu
是一个更大的"占位符" ULONG_MAX
.
我希望得到相同的输出,但我得到一个模糊的输出
38654705663
Run Code Online (Sandbox Code Playgroud)
不ULONG_MAX
应该是一个常数吗?为什么会改变?另外,在寻求答案时,我偶然发现了这一点.
我理解标准提到"最小"这个术语的论点,但是当我测试它时CHAR_MAX
(即试图CHAR_MAX
用%llu
说明符打印),我得到了
38654705663
Run Code Online (Sandbox Code Playgroud)
这与我char
在C中读到的所有内容相矛盾.
真的希望有人能解决这方面的困惑.
每当我想使用优先级队列(默认情况下创建一个max-heap)创建一个min-heap时,我需要传递一个比较器以及一个需要排序的类型的向量,如下所示:
std::priority_queue<int, std::vector<int>, std::greater<int> > pq;
Run Code Online (Sandbox Code Playgroud)
我们为什么要做这个?为什么我们不需要同样的最大堆实现?
I am trying to solve a particular leetcode problem but I can't seem to figure out where I am going wrong.
The question is this one:https://leetcode.com/problems/group-anagrams/ and my code is:
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& str) {
unordered_map<string, vector<int>> map;
vector<string> newstr = str;
int size = str.size();
//pushing those indices of `str` into the map which share common permutation
for(int i=0; i<size; i++){
sort(newstr[i].begin(), newstr[i].end());
map[newstr[i]].push_back(i);
}
vector<vector<string>> ans;
int i=0;
for(auto itr: map){
int v_size = …
Run Code Online (Sandbox Code Playgroud) 我在二分搜索实现上遇到了很多困难,尤其是
r
和l
)r=mid
或r=mid-1
我试图实施upper_bound
from STL
,但无法得到正确的答案。这是我的代码。
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n+2);
// adding 0 in front to avoid out of bounds error
// when looking for a[m-1]
a[0]=0;
for(int i=1; i<=n; i++)
cin >> a[i];
// adding a big element at the end to return that index
// when required element is greater than all elements
a[n]=INT_MAX;
// q …
Run Code Online (Sandbox Code Playgroud) c ×3
c++ ×3
certificate ×1
docker ×1
javascript ×1
mongodb ×1
postman ×1
scanf ×1
stl ×1
variables ×1