Coder Social home page Coder Social logo

找茬 about acm-cheat-sheet HOT 5 OPEN

lzl124631x avatar lzl124631x commented on July 23, 2024
找茬

from acm-cheat-sheet.

Comments (5)

lushl9301 avatar lushl9301 commented on July 23, 2024

'''顺便问一下, 有什么快捷方法把我贴上去的代码直接转成"代码样式"嘛? 我是每行行首手动复制了四个空格...有些麻烦'''

有些ide(比如eclipse) 支持一键自动ident。全选之后 ctrl + shift + F 就会自动把缩进调整好。
(虽然还是有点点麻烦……XD)

from acm-cheat-sheet.

lzl124631x avatar lzl124631x commented on July 23, 2024

希尔排序的shell_insert里面:
for (j = i - gap; tmp < a[j] && j >= start; j -= gap) {
这里应该先判断 j >= start 再 访问a[j].
另外感觉你的shell_insert不应该是从 i = start+gapi < end, 那样会导致很多元素重复进行判断插入. 下面是我的代码, i是每次插入排序的起始点, j是每次插入的当前点, k是每次插入向前扫描的指针.

void shellInsertionSort(int A[], int len){
    if(!A || len < 2) return;
    int gap = len;
    while(gap > 1){
        gap = gap / 3 + 1;
        for(int i = 0; i < gap; ++i){
            for(int j = i + gap; j < len; j += gap){
                int k = j, tmp = A[j];
                for(; k > i && A[k - gap] > tmp; k -= gap){
                    A[k] = A[k - gap];
                }
                A[k] = tmp;
            }
        }
    }
}

还有, 我问的不是IDE中如何自动indent, 而是这GitHub中如何自动让代码变成上面这种框框. 看了一下这里https://help.github.com/articles/github-flavored-markdown, 原来用 ``` 包裹起来就好了.

from acm-cheat-sheet.

soulmachine avatar soulmachine commented on July 23, 2024

感谢找茬,要多多找茬,我有时间会仔细看一下:)

from acm-cheat-sheet.

yinwuzhe avatar yinwuzhe commented on July 23, 2024

作者你好,我刚刚看这本书,对于第一章说的一点有点怀疑
“判断一个整数是否是为奇数,用 x % 2 != 0,不要用 x % 2 == 1,因为 x 可能是
负数。”

但是我经过实验发现即使是复数,使用 x % 2 == 1也可以负数的奇数可以找出来。。

实验平台:x86-64
代码:
#include <stdio.h>

int main()
{
int num;
scanf("%d",&num);
if((num%2)==1)
printf("%d is odd number\n", num);
return 0;
}

运行结果:
[root@localhost soulmachine]# ./cha1
-9
-9 is odd number

gcc版本号:
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)

from acm-cheat-sheet.

soulmachine avatar soulmachine commented on July 23, 2024

这个技巧是跟编译器相关的,因为C++标准没有规定负数除法,所以不同的编译器是不同的

现代的gcc , vc的等编译器尽可能与主流保持一致,所以我的这个技巧已经过时了

On Friday, August 8, 2014, yinwuzhe [email protected] wrote:

作者你好,我刚刚看这本书,对于第一章说的一点有点怀疑
“判断一个整数是否是为奇数,用 x % 2 != 0,不要用 x % 2 == 1,因为 x 可能是
负数。”

但是我经过实验发现即使是复数,使用 x % 2 == 1也可以负数的奇数可以找出来。。

实验平台:x86-64
代码:
#include

int main()
{
int num;
scanf("%d",&num);
if((num%2)==1)
printf("%d is odd number\n", num);
return 0;
}

运行结果:
[root@localhost soulmachine]# ./cha1
-9
-9 is odd number

gcc版本号:
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)


Reply to this email directly or view it on GitHub
#13 (comment)
.

My tech blog: http://www.soulmachine.me
My GitHub: https://github.com/soulmachine
My LinkedIn: http://www.linkedin.com/in/soulmachine/
My Sina Weibo: http://weibo.com/soulmachine

from acm-cheat-sheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.