Created
May 2, 2013 06:34
-
-
Save seiyaKai/5500508 to your computer and use it in GitHub Desktop.
[宿題]アルファベットの頻度分析をするプログラムを作ろう。大文字と小文字は同じ文字として扱う。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
class HindoCheck | |
{ | |
public: | |
void check(std::string in_str); | |
private: | |
int result[26]; | |
}; | |
void HindoCheck::check(std::string in_str){ | |
std::cout << "set '" << in_str << "' length " << in_str.length() << std::endl; | |
for(int i = 0 ; i < sizeof(result) / sizeof(result[0]) ; i++){ | |
result[i] = 0; | |
} | |
for(int n = 0 ; n < in_str.length() ; n++){ | |
in_str[n] = tolower(in_str[n]); | |
int in_str_dec = (int)in_str[n]; | |
if(in_str_dec > 96 && in_str_dec < 123){ | |
result[in_str_dec-97]++; | |
} | |
} | |
for(int j = 0 ; j < sizeof(result) / sizeof(result[0]) ; j++){ | |
std::cout << (char)(j+97) << " = " << result[j] << std::endl; | |
} | |
} | |
int main(int argc , const char *argv){ | |
HindoCheck hc; | |
std::string str; | |
std::cout << "string > "; | |
//std::cin >> str; | |
getline(std::cin,str); | |
hc.check(str); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment