这段代码来自 Geeks for Geeks Algorithms 部分,我不明白这部分
int n = sizeof(arr) / sizeof(arr[0]);
Run Code Online (Sandbox Code Playgroud)
在主函数中,特别是为什么使用 sizeof(arr[0]) 的除法会导致数组中实际元素数量的一半。希望有人可以向我解释这一点。
// C++ code to linearly search x in arr[]. If x
// is present then return its location, otherwise
// return -1
#include <iostream>
using namespace std;
int search(int arr[], int n, int x)
{
int i;
for (i = 0; i < n; i++)
if (arr[i] == x)
return i;
return -1;
}
int main(void)
{
int arr[] = { 2, 3, 4, 10, …Run Code Online (Sandbox Code Playgroud) 我目前陷入了请求直通的困境。我需要使用步骤函数管道处理来自标头和请求正文的信息。我正在使用 REST API 网关,该网关在集成请求中具有以下映射模板
#set($data = $util.escapeJavaScript($input.json('$')))
{
"input": "{ \"input\": $data, \"stageVariables\" : { #foreach($key in $stageVariables.keySet()) \"$key\" : \"$util.escapeJavaScript($stageVariables.get($key))\" #if($foreach.hasNext),#end #end } }",
"stateMachineArn": "arn:aws:states:eu-west-1:xxxxxxxxxxxx:stateMachine:StateMachine-1"
}
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。如果我使用 lambda 事件访问标头,它将是 event['headers']['Authorization'] 但我仅将请求正文作为步骤函数的输入。
当我将数据流模拟器用于整个请求,然后将 JsonPath 放入我的状态机模板中时,它仍然没有为我提供标头和正文作为输入。
有人可以帮我吗?