Exemplo n.º 1
0
int main(int argc, char const *argv[])
{
  char str[] = "abcdefg";
  printf("%s\n", str );
  LeftRotateString(str, (int)sizeof(str) - 1, 2);
  printf("%s\n", str );
  return 0;
}
// ====================测试代码====================
void Test(const char* testName, char* input, int num, const char* expectedResult)
{
    if(testName != nullptr)
        printf("%s begins: ", testName);

    char* result = LeftRotateString(input, num);

    if((input == nullptr && expectedResult == nullptr)
        || (input != nullptr && strcmp(result, expectedResult) == 0))
        printf("Passed.\n\n");
    else
        printf("Failed.\n\n");
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	char str[100];
	int n;
	int m;

	printf("Please input a string: ");
	scanf("%s", str);
	n = strlen(str);
	printf("The last m letters will be moved to the beginning.\n");
	printf("Define m: ");
	scanf("%d", &m);
	LeftRotateString(str, n, n - m);
	printf("The String after moved: %s\n", str);

	return 0;
}