当前位置:网站首页>Judge whether a string is a full letter sentence

Judge whether a string is a full letter sentence

2022-07-05 17:05:00 Daily study of bald girls

Judge whether a string is a full letter sentence

LeetCode Day 2
subject : Give a string consisting of only lowercase English letters sentence , Judge sentence Is it a full letter sentence . If it is , return true ; otherwise , return false .

Topic link :https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram/

Full letter sentence : A sentence contains each letter of the English alphabet at least once .

Implementation code

#include<stdio.h>
#include<string.h>
bool checkIfPangram(char * sentence)
{
    
    char zimu[30]={
    0};
    int i,j,length;
    length=strlen(sentence);
    for(i=0;i<length;i++)
     {
    
       zimu[sentence[i]-'a']++;
     }
        for(j=0;j<26;j++)
        {
    
            if(zimu[j]==0)
             return false;
        }
          return true;      
}
int main()
{
    
    char senten[1005];
    scanf("%s",&senten);
    bool flag = checkIfPangram(senten);
    printf("%d",flag);
}

Running results :
Not all alphabetic sentences , Output 0
 Insert picture description here
It's a full alphabetic sentence , Output 1
 Insert picture description here

原网站

版权声明
本文为[Daily study of bald girls]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140510252349.html