【每日面試題】在字符串中刪除特定的字符

 題目:輸入兩個字符串,從第一字符串中刪除第二個字符串中所有的字符。例如,輸入”They are students.”和”aeiou”,

則刪除之後的第一個字符串變成”Thy r stdnts.”。

代碼:

void DeleteString(char *str,char *des)
{
 int phash[256]={0};
 while(*des!='\0')
 {
  phash[*des]=1;
  des++;
 }
 char *s=str;
 char *f=str;
 while(*f!='\0')
 {
  
  if(phash[*f]!=1)
  {
   *s=*f;
   s++;
  }
  f++;

 }
 *s='\0';
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章