C ++中的一些技巧 [英] Some techniques in C++

查看:90
本文介绍了C ++中的一些技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中使用了位掩码技术和XOR操作,请您解释一下这些技术以及替代这些方法的替代方法是什么?



我尝试过:



in this piece of code bit masking technique and XOR operation are used, could you please explain me about these techniques and what's the alternative ways instead of these methods?

What I have tried:

some techniques in C++

推荐答案

Quote:

for(i = 1; i< = n; i ++){

if(i == pow(2,p)){Final [i] = 0;

p ++;}

else {

Final [i] = b [j];

j ++;

}}

for (i = 1; i <= n; i++){
if (i == pow(2, p)){ Final[i] = 0;
p++;}
else{
Final[i] = b[j];
j++;
}}



XOR 在上面的代码中使用。



你应该理解我们(或者,至少我)不知道这种(不完整的)代码的目的。


No XOR used in the above piece of code.

You should understand we (or, at least I) have no idea about the purpose of such (incomplete) code.


没有上下文,你的代码没有意义,我们无法知道发生了什么,因为它依赖于我们不知道的其他代码。

当你发布一段代码时,这是一个好主意发布一段自主代码(我们可以编译和运行的代码)(包括数据)。

-----

学会正确缩进代码,它显示了它的结构,有助于阅读和理解。它还有助于发现结构错误。

Without context, your code is meaningless, we have no way to know what is going on because it depend on other piece of code that we don't know.
When you post a piece of code, it is a good idea to post an autonomous piece of code (code that we can compile and run)(this include the data).
-----
Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
for (i = 1; i <= n; i++){
  if (i == pow(2, p)){
    Final[i] = 0;
    p++;
  }
  else{
    Final[i] = b[j];
    j++;
  }
}




for (i = 1; i < pow(2, r); i = pow(2, x)){
  for (j = 1; j <= n; j++){
    if ((i&j) == i)
      Final[i] ^= Final[j];
  }
  x++;
  std::cout << std::endl << i <<" " <<Final[i] ;
}





专业程序员的编辑器具有此功能以及其他功能,例如括号匹配和语法高亮。

Notepad ++主页 [ ^ ]

ultraedit [ ^ ]


这篇关于C ++中的一些技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆