c_cpp GFG检查字符串是否为Isogram

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp GFG检查字符串是否为Isogram相关的知识,希望对你有一定的参考价值。

#include <bits/stdc++.h>
using namespace std;

// #Maps #Hashing #GFG #Problem
// https://practice.geeksforgeeks.org/problems/check-if-a-string-is-isogram-or-not/0/?track=SP-Hashing

bool isIsogram(string x){
    map < char, bool > m;
    for(int i=0;i<x.size();i++){
        if( m[ x[i] ]==true ){
            return false;   // if char is repeated return false
        }
        m[ x[i] ]=true;
    }
    return true;
}

int main() {
	int t;
	cin>>t;
	while(t--){
	    string x;
	    cin>>x;
	    if(isIsogram(x)==true){
	        cout<<"1"<<endl;
	    }else{
	        cout<<"0"<<endl;
	    }
	}
	return 0;
}

以上是关于c_cpp GFG检查字符串是否为Isogram的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp GFG-门

c_cpp GFG骑士步行

c_cpp GFG发现号码

c_cpp GFG排序矩阵行

c_cpp GFG最低成本路径

c_cpp GFG重复和失踪