- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
// https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/code/c/1.1%EF%BC%9A%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2.c
#include <stdio.h>
#include <string.h>
//字符串旋转问题,例如abcdef 左旋2位 变成 cdefab
//暴力移位法
void leftShift1(char * arr, int n)
{
size_t tmpLen = strlen(arr);
char tmpChar;
int i, j;
if (n >= 0)
{
for (i = 0; i < n; i++)
{
tmpChar = *arr;
for (j = 0; j < tmpLen - 1; j++)
{
*(arr + j) = *(arr + j + 1);
}
*(arr + tmpLen - 1) = tmpChar;
}
}
else
{
for (i = 0; i < -n; i++)
{
tmpChar = *(arr + tmpLen - 1);
for (j = tmpLen - 1; j > 0; j--)
{
*(arr + j) = *(arr + j - 1);
}
*arr = tmpChar;
}
}
}
Копаясь в гитхабе, нашел я тут The Art Of Programming By July, написанный каким-то китайцем.
https://github.com/julycoding/The-Art-Of-Programming-By-July
j123123 18.08.2017 16:30 # +1
bormand 18.08.2017 18:35 # +1
j123123 18.08.2017 18:40 # +1
Stallman 18.08.2017 18:41 # 0
bormand 18.08.2017 18:46 # +3