Comments (5)
'''顺便问一下, 有什么快捷方法把我贴上去的代码直接转成"代码样式"嘛? 我是每行行首手动复制了四个空格...有些麻烦'''
有些ide(比如eclipse) 支持一键自动ident。全选之后 ctrl
+ shift
+ F
就会自动把缩进调整好。
(虽然还是有点点麻烦……XD)
from acm-cheat-sheet.
希尔排序的shell_insert里面:
for (j = i - gap; tmp < a[j] && j >= start; j -= gap) {
这里应该先判断 j >= start 再 访问a[j].
另外感觉你的shell_insert不应该是从 i = start+gap
到 i < 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.
感谢找茬,要多多找茬,我有时间会仔细看一下:)
from acm-cheat-sheet.
作者你好,我刚刚看这本书,对于第一章说的一点有点怀疑
“判断一个整数是否是为奇数,用 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.
这个技巧是跟编译器相关的,因为C++标准没有规定负数除法,所以不同的编译器是不同的
现代的gcc , vc的等编译器尽可能与主流保持一致,所以我的这个技巧已经过时了
On Friday, August 8, 2014, yinwuzhe [email protected] wrote:
作者你好,我刚刚看这本书,对于第一章说的一点有点怀疑
“判断一个整数是否是为奇数,用 x % 2 != 0,不要用 x % 2 == 1,因为 x 可能是
负数。”但是我经过实验发现即使是复数,使用 x % 2 == 1也可以负数的奇数可以找出来。。
实验平台:x86-64
代码:
#includeint 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 numbergcc版本号:
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)
- 生成可重集的排列 HOT 1
- heap_sort 内存泄露 HOT 1
- cpp 和 c 的版本有差别吗 HOT 1
- Java版是没内容吗? HOT 1
- 小拼写错误, typo
- 陈硕的模板编译报错Undefined control sequence HOT 3
- README.md上的错别字 HOT 4
- 北美求职群404
- 百度网盘链接已经失效 HOT 2
- test case没通过
- 字符串匹配的总结表分行是否有误
- docker编译后的pdf间隔比较窄 HOT 1
- 用VSCode编译,报错说找不到多个字体
- 想问下大佬,这个工具是用来干嘛的
- PDF中的中文,复制到记事本中是乱码 HOT 1
- 队列中的queue_back函数有错误? HOT 2
- 去除代码中的"std::"前缀 HOT 1
- 下一个排列 HOT 1
- Font Family and Comment Style HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acm-cheat-sheet.