題目 https://leetcode-cn.com/problems/long-pressed-name/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define bool int
#define true 1
#define false 0
bool isLongPressedName(char * name, char * typed){
if(name == NULL && typed == NULL)//常規判斷
return true;
if(name == NULL || typed == NULL)//常規判斷
return false;
if(name[0] != typed[0])//常規判斷
return false;
int i=1,j=1;
while(name[i] != 0x00 && typed[j] != 0x00){//常規判斷
if(name[i] == typed[j]){//相等 比較下一個字符
i++;
j++;
continue;
}
if(typed[j] == typed[j-1]){//typed估計有多個相同的字符
j++;
}else{
break;//既不是有多個相同的字符 那就是不符合規範了
}
}
if(name[i] == 0x00){
while(typed[j] != 0x00){
if(typed[j] != name[i-1])//確保結尾的都是相同字符 a 和 ab 是兩個不同名字 a 和 aa 是兩個相同名字
return false;
j++;
}
return true;
}
return false;
}
int main(){
{
printf("%d\n",isLongPressedName("alex","aaleex"));
}
{
printf("%d\n",isLongPressedName("saeed","ssaaedd"));
}
{
printf("%d\n",isLongPressedName("laiden","laiden"));
}
{
printf("%d\n",isLongPressedName("a","aa"));
}
{
printf("%d\n",isLongPressedName("a","ab"));
}
}