26文字の英字が数字に対応する奇妙な意味

6241 ワード

 

if:
  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
thus:
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 so:
ハードワーク
  H A R D W O R K 8 1 18 4 23 15 18 11 = 98%
Knowledge(知識)
  K N O W L E D G E 11 14 15 23 12 5 4 7 5 = 96%
  Love
  L O V E12 15 22 5 = 54%
Health(健康)=54%
ラッキー
  L U C K12 21 3 11 = 47%
       M O N E Y = 13 15 14 5 25 = 72%
では、何が生活を100%円満にすることができますか?
どの問題にも合理的な解決策があるかもしれない.
ATTITUDE=100%
#include
#include
#include
 
#define IS_UPPER(x)(x>='A'&&x<='Z')/大文字かどうかを判断します.
#define IS_LOWER(x)(x>='a'&&x<='z')/小文字かどうかを判断します.
 
using namespace std;
 
 
 
inline int Get_words(char* words)
{
cout << "please enter a words(english)!"<< endl;
fgets(words, 100, stdin);
//stdinは、ファイルではなくキーボードから入力することを示します.
//printf("%s", a);//ここ%s後はありませんが、出力はリターンがあります
return strlen(words);
}
 
 
void Case_num(int& sum, const char* words, const map& num_upper, const map& num_lower)
{
 
for (int j = 0; j < strlen(words);++j)
{
//cout << words[j] << endl;
//Nonum_lower.find()
if (IS_UPPER(words[j]))
{
for (map::const_iterator it_upper = num_upper.begin(); it_upper != num_upper.end(); it_upper++)
{
if (it_upper->second == words[j])
sum += it_upper->first;
}
 
}
if (IS_LOWER(words[j]))
{
for (map::const_iterator it_lower = num_lower.begin(); it_lower != num_lower.end(); it_lower++)
{
if (it_lower->second == words[j])
{
sum += it_lower->first;
}
}
}
 
}
 
}
//Cプロセス向けの実装
int main01()
{
 
//1数字とアルファベットの値を保存
map Nonum_upper;
map Nonum_lower;
char words[100];
int sum = 0;
 
 
int* a = new int[26];
for (int i = 0; i < 26; i++)
{
a[i] = i + 1;
//printf("%d\t",a[i]);
}
 
 
string str = "abcdefghijklmnopqrstuvwxyz";
const char lowerLetter[] = "abcdefghijklmnopqrstuvwxyz";
const char upperLetter[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
for (int i = 0; i < 26; i++)
{
Nonum_upper[i + 1] = upperLetter[i];
Nonum_lower[i + 1] = lowerLetter[i];
}
 
 
//2計算する単語を画面から取得
bool out = false;
while (true)
{
Get_words(words);
string s = words;
if (s == "break") out = true;
if (out) break;
//大文字と小文字に対応する数字を取得して加算する
Case_num(sum, words, Nonum_upper, Nonum_lower);
cout << "words = "<< words << ""<< "the number is "<< sum << "%"<< endl;
sum = 0;
}
cout << "Thank you using the system!"<< "Have a nice day!"<<::endl;
 
system("pause");
 
 
 
return 0;
}
 
class vocab
{
private:
//数字と大文字と小文字の関連付け
map num_upper;
map num_lower;
//外付けで得た単語を保存する
char vocabulary[100];
 
int sum;//最後の計算結果
const int num;//26文字
const char* lowerLetter;
const char* upperLetter;
 
 
public:
//キーボードから語彙をもらう
int Case_letter(const char* words);
inline int Get_vocab(char* words);
friend int Get_sum(vocab& vc);
inline friend void Clear_sum( vocab* vc);
int Get_Sum();
void map_letter();
vocab();
~vocab();
 
 
 
};
 
vocab::vocab() :sum(0), num(26)
{
lowerLetter = "abcdefghijklmnopqrstuvwxyz";
upperLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
for (int i = 0; i < this->num; i++)
{
num_upper[i + 1] = upperLetter[i];
num_lower[i + 1] = lowerLetter[i];
}
}
 
vocab::~vocab()
{
lowerLetter = NULL;
upperLetter = NULL;
 
}
 
int vocab::Case_letter(const char* words)
{
for (int j = 0; j < strlen(words);++j)
{
//cout << words[j] << endl;
//Nonum_lower.find()
if (IS_UPPER(words[j]))
{
for (map::const_iterator it_upper = num_upper.begin(); it_upper != num_upper.end(); it_upper++)
{
if (it_upper->second == words[j])
sum += it_upper->first;
}
}
if (IS_LOWER(words[j]))
{
for (map::const_iterator it_lower = num_lower.begin(); it_lower != num_lower.end(); it_lower++)
{
if (it_lower->second == words[j])
{
sum += it_lower->first;
}
}
}
 
}
 
return sum;
 
}
inline int vocab::Get_vocab(char* words)
{
cout << "please enter a words(english)!"<< endl;
fgets(words, 100, stdin);//stdinは、ファイルではなくキーボードから入力することを示します.
//printf("%s", words);//ここ%s後はありませんが、出力はリターンがあります
return strlen(words);
}
 
 
 
int Get_sum(vocab& vc)
{
return vc.sum;
}
 
int vocab::Get_Sum()
{
return sum;
}
inline void Clear_sum(vocab* vc)
{
vc->sum = 0;
}
 
//C++オブジェクト向けの実装
int main()
{
char voc[100];
vocab vo;
bool out = false;
while (true)
{
vo.Get_vocab(voc);
string s = voc;
if (s == "break") out = true;
if (out) break;
 
cout << voc << "is "<< vo.Case_letter(voc) << "% "<< endl;
Clear_sum(&vo);
}
//printf("%s is %d%", voc, Get_sum(vo));
//printf("%s is %d%", voc, vo.Get_Sum());
cout << "Thank you using the system!"<< "Have a nice day!"<<::endl;
return 0;
}