Not Found

題目描述

You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.

Constraints
1≤|S|≤105 (|S| is the length of string S.)
S consists of lowercase English letters.

輸入

Input is given from Standard Input in the following format:
S

輸出

Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.

樣例輸入

atcoderregularcontest

樣例輸出

b

提示

The string atcoderregularcontest contains a, but does not contain b.

題解:水題,將字符串所有字母都編程數字加入相同數組,最後掃一次看是否有字母沒有出現過。

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a[30]={0},i=0,k=-1,s;
    string str;
    cin>>str;
    while(str[i])//將字符串所有字母讀入
    {
        s=str[i]-'a'+1;
        a[s]++;
        i++;
    }
    for(int j=1;j<=26;j++)//26個字母掃一遍,遇0停止
    {
        if(a[j]==0)
        {
            k=1;
            printf("%c\n",'a'+j-1);
            break;
        }
    }
    if(k==-1)
    {
        cout<<"None"<<endl;
    }
}

 

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