赞
踩
void left_revolve(char *p,int str) { int k = 0; scanf("%d",&k); int i = 0; for ( i = 0; i < k; i++) { char* frist = p; char* second = p + 1; int j = 0; for ( j = 0; j < str-1; j++) { if (*frist !='\0') { char tmp = *frist; *frist = *second; *second = tmp; frist++; second++; } } } } int main() { char arr[] = "abcd"; int str = strlen(arr); left_revolve(arr,str); printf("%s", arr); return 0; }
#include<string.h> void left_move(char* a, int k, int sz) { int i = 0; for ( i = 0; i <k; i++) { char tmp = *a; int j = 0; for ( j = 0; j < sz-1; j++) { //前面那个元素和后面那个元素交换 *(a + j) = *(a + j + 1); } *(a + sz - 1) = tmp; } } int main() { //字符串左旋 char arr[] = "ABCDEF"; int sz = strlen(arr); int k = 0; scanf("%d", &k); left_move(arr,k, sz); printf("%s", arr); return 0; }
#include<assert.h> void reverse(char* left, char* right) { assert(left); assert(right); while (left<right) { char tmp = *left; *left = *right; *right = tmp; left++; right--; } } void left_move(int *arr,int k,int str) { reverse(arr, arr + k-1); reverse(arr + k , arr + str - 1); reverse(arr, arr + str - 1); } int main() { char arr[] = "ABCDEF"; int str = strlen(arr); int k = 3; left_move(arr, k, str); return 0; }
int is_right(char* arr1, char* arr2) { int i = 0; int ret = strlen(arr1); for ( i = 0; i <ret ; i++) { char tmp = *arr1; int j = 0; for ( j = 0; j < ret-1; j++) { *(arr1 + j) = *(arr1 + j + 1); } *(arr1 + ret - 1) = tmp; if (*arr1 == *arr2) { return 1; } } return 0; } int main() { char arr1[] = "ABCDE"; char arr2[] = "EDCBA"; int ret =is_right(arr1, arr2); if (ret == 1) { printf("yes"); } else { printf("no"); } return 0; }
int is_right(char* arr1, char* arr2)
{
int str = strlen(arr1);
int str2 = strlen(arr2);
if (str == str2)
{
strncat(arr1, arr1, str);
char *ret = strstr(arr1, arr2);
return ret!=NULL;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。