给定一个整数数组,您必须找到两个XOR最大的元素.
有天真的方法 - 只需挑选每个元素和xoring与其他元素,然后比较结果找到对.
除此之外,有没有有效的算法?
我正在将json数据渲染到html页面:
<div ng-if="'done'={{task_detail.status}}">
<b>Status :</b>
<p class="label label-success">{{task_detail.status}}</p>
<br>
<br>
<div class="progress progress-striped">
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:{{task_detail.percentage_finished}}%">
<span class="sr-only">{{task_detail.percentage_finished}}% Complete</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我渲染的json数据:
{
"id": 1,
"title": "Launch an EC Instance",
"desc": "Needed an EC instance to deploy the ccr code",
"status": "done",
"percentage_finished": 100
}
Run Code Online (Sandbox Code Playgroud)
问题:HTML视图不可见,因为控件没有移动到内部ng-if
.语法是否正确?
给定长度为n的值的数组,是否有一种方法可以计算插入排序执行的交换次数,以便在时间上优于O(n 2)对该数组进行排序?
例如 :
arr[]={2 ,1, 3, 1, 2}; // Answer is 4.
Run Code Online (Sandbox Code Playgroud)
算法:
for i <- 2 to N
j <- i
while j > 1 and a[j] < a[j - 1]
swap a[j] and a[j - 1] //I want to count this swaps?
j <- j - 1
Run Code Online (Sandbox Code Playgroud) 这三种输入函数在编程语言中有什么区别.他们以不同的方式相互输入吗?
1.getchar_unlocked()
#define getcx getchar_unlocked
inline void inp( int &n )
{
n=0;
int ch=getcx();int sign=1;
while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}
while( ch >= '0' && ch <= '9' )
n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
n=n*sign;
}
Run Code Online (Sandbox Code Playgroud)
2.scanf("%d",&n)
3.cin>>n
输入整数时哪一个花费的时间最少?
我在c ++中使用THese头文件,其中所有3个用c ++运行;
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
Run Code Online (Sandbox Code Playgroud) main(a){printf(a="main(a){printf(a=%c%s%c,34,a,34);}",34,a,34);}
Run Code Online (Sandbox Code Playgroud)
编译后它是如何复制的?在printf函数中编写34的作用是什么?
我在两个代码中做同样的事情.
在代码1中:我使用了a char *
并使用malloc
in 分配空间main
.
在代码2中:我使用了一个char
数组用于相同的目的.但为什么输出会有所不同?
代码1:
struct node2
{
int data;
char p[10];
}a,b;
main()
{
a.data = 1;
strcpy(a.p,"stack");
b = a;
printf("%d %s\n",b.data,b.p); // output 1 stack
strcpy(b.p,"overflow");
printf("%d %s\n",b.data,b.p); // output 1 overflow
printf("%d %s\n",a.data,a.p); // output 1 stack
}
Run Code Online (Sandbox Code Playgroud)
代码2:
struct node1
{
int data;
char *p;
}a,b;
main()
{
a.data = 1;
a.p = malloc(100);
strcpy(a.p,"stack");
b = a;
printf("%d %s\n",b.data,b.p); //output 1 stack
strcpy(b.p,"overflow");
printf("%d %s\n",b.data,b.p); …
Run Code Online (Sandbox Code Playgroud) 在这里,我对输出有一些疑问.
为什么输出相同?
int (*r)[10];
printf("r=%p *r=%p\n",r,*r);
return 0;
Run Code Online (Sandbox Code Playgroud)
平台 - GCC UBUNTU 10.04
我正在使用API数据填充kendo - grid,但是在一个字段上添加验证也会自动为每个其他字段工作.
这是kendo-dataSource中的架构:
schema: {
model: {
id : "id",
fields: {
id: { editable: false, type: 'number'},
name: { editable: true, type : "string" },
unique_url: { editable: true , type: 'string'},
image_url : { editable: true, type : "string" },
title: {type : "string", validation: {
required: true,
validateTitle: function (input) {
console.log("I am inside validation",input.val());
if (input.val().length > 5) {
input.attr("data-validateTitle-msg", "Max length exceeded 5 characters only");
return false;
}
return true;
}
}
},
body: …
Run Code Online (Sandbox Code Playgroud) 使用Angular Material2 mat-selection-list,能够识别当前选项是选中还是未选中[布尔].
compnenent.html
<mat-selection-list #shoes (selectionChange)="onSelection($event, shoes.selectedOptions)" >
<mat-list-option *ngFor="let shoe of typesOfShoes" [value]='shoe'>
{{shoe}}
</mat-list-option>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)
component.ts
export class ListSelectionExample {
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
onSelection(e, v){
console.error(e.option.selected,v);
}
}
Run Code Online (Sandbox Code Playgroud)
e.option.selected
通知当前选项是选中还是未选中.
如何识别当前选定的值?尝试使用ngModel和ngModelChange的多个组合并单击,对我来说没有任何作用.
https://stackblitz.com/edit/angular-eyjdfp-qgjhvd?file=app%2Flist-selection-example.ts
尝试编译以下rust
代码以wasm
使其与现有js兼容运行。尝试从函数返回哈希映射值。
库文件
use wasm_bindgen::prelude::*;
use std::collections::HashMap;
#[wasm_bindgen]
pub fn get_transformed_filters()-> HashMap<i32, i32> {
let mut hm = HashMap::new();
for i in 1..9990000 {
hm.insert(i + i, i * i);
}
return hm
}
Run Code Online (Sandbox Code Playgroud)
运行命令后控制台错误wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling hello-wasm v0.1.0 (/Users/mfe/ui/rustService/test-wasm)
error[E0277]: the trait bound `HashMap<i32, i32>: IntoWasmAbi` is not satisfied
--> src/lib.rs:15:1
|
15 | #[wasm_bindgen]
| ^^^^^^^^^^^^^^^ the trait `IntoWasmAbi` is not implemented for `HashMap<i32, …
Run Code Online (Sandbox Code Playgroud) c ×4
arrays ×3
c++ ×3
algorithm ×2
pointers ×2
angular ×1
angular6 ×1
angularjs ×1
ascii ×1
kendo-grid ×1
kendo-ui ×1
linux ×1
printf ×1
quine ×1
rust ×1
rust-cargo ×1
rust-wasm ×1
scanf ×1
sorting ×1
struct ×1
validation ×1
wasm-bindgen ×1
webassembly ×1
xor ×1