重庆做网站建设公司哪家好/营销型外贸网站建设
题目: 给定两个字符串 s1 和 s2, 请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。
示例1:
输入: s1 = "abc", s2 = "bca"
输出: true
示例2:
输入:s1 = "abc", s2 = "bad"
输出: false
说明:
0 <= len(s1) <= 100
0 <= len(s2) <= 100
c解答:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef int bool;
#define false 0
#define true 1
bool CheckPermutation(char* s1, char* s2)
{char *p = s1, *q = s2;while(*p != '\0' && *q != '\0'){p++;q++;}if(*p != '\0' || *q != '\0') return false;while(*s1 != '\0'){q = s2;while(*q != '\0'){if(*s1 == *q) {*q = ' ';break;}q++;}if(*q=='\0') return false;s1++;}if(*q=='\0') return false;return true;}int main()
{char a[] = "abb";char b[] = "baa";bool result = CheckPermutation(a, b);if(result){printf("True\n");}else{printf("False\n");}return 0;
}