小编Ani*_*rya的帖子

数组中的两个元素,其xor是最大的

给定一个整数数组,您必须找到两个XOR最大的元素.

有天真的方法 - 只需挑选每个元素和xoring与其他元素,然后比较结果找到对.

除此之外,有没有有效的算法?

arrays algorithm bit-manipulation xor

44
推荐指数
3
解决办法
3万
查看次数

ng-if(Angularjs)不起作用

我正在将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.语法是否正确?

angularjs

24
推荐指数
2
解决办法
7万
查看次数

计算插入次数的有效方法是按递增顺序排序整数数组

给定长度为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)

c c++ arrays sorting algorithm

15
推荐指数
2
解决办法
1万
查看次数

getchar_unlocked()VS scanf()VS cin

这三种输入函数在编程语言中有什么区别.他们以不同的方式相互输入吗?

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)

c++ scanf

13
推荐指数
2
解决办法
2万
查看次数

自我复制程序

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的作用是什么?

c linux printf ascii quine

10
推荐指数
1
解决办法
4725
查看次数

字符数组和指针之间的区别

我在两个代码中做同样的事情.

在代码1中:我使用了a char *并使用mallocin 分配空间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)

c c++ arrays struct pointers

8
推荐指数
1
解决办法
677
查看次数

指向整数数组的指针

在这里,我对输出有一些疑问.

为什么输出相同?

   int (*r)[10];
   printf("r=%p  *r=%p\n",r,*r);
   return 0;
Run Code Online (Sandbox Code Playgroud)

平台 - GCC UBUNTU 10.04

c pointers multidimensional-array

5
推荐指数
1
解决办法
1063
查看次数

Kendo-Grid列字段验证

我正在使用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)

validation kendo-ui kendo-grid kendo-dataviz

5
推荐指数
1
解决办法
2万
查看次数

angular6材料mat-selection-list中的当前选定值

使用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

angular-material angular-material2 angular angular6

5
推荐指数
3
解决办法
1万
查看次数

“HashMap&lt;i32, i32&gt;”未实现特征“IntoWasmAbi”

尝试编译以下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)

rust rust-cargo webassembly wasm-bindgen rust-wasm

5
推荐指数
0
解决办法
3962
查看次数