题目:
解题思路:
字符串拼接,先遍历复制从下标为 target 开始的 len - target 位字符,再遍历复制前 target位字符至末尾。
char* dynamicPassword(char* password, int target) {
int len = strlen(password);
// int num = 0;
int i = 0;
char* result = (char*) malloc(sizeof(char) * (len+1));
for (; i+target < len; i++) {
result[i] = password[i+target];
}
for (int j = 0; j < target; j++) {
result[i] = password[j];
i++;
}
result[i] = '\0';
return result;
}