26个英文字母对应数字的奇妙意义

 

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:

       Hard work (努力工作)

  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%

  Luck(好运)

  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后没有\n,但输出是有回车的

return strlen(words);

}

 

 

void Case_num(int& sum, const char* words, const map<int, char>& num_upper, const map<int, char>& num_lower)

{

 

for (int j = 0; j < strlen(words); ++j)

{

//cout << words[j] << endl;

//Nonum_lower.find()

if (IS_UPPER(words[j]))

{

for (map<int, char>::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<int, char>::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<int, char> Nonum_upper;

map<int, char> 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\n") 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!\n" << "Have a nice day!\n" << ::endl;

 

system("pause");

 

 

 

return 0;

}

 

class vocab

{

private:

//数字和大小写字母关联

map<int, char> num_upper;

map<int, char> 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<int, char>::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<int, char>::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后没有\n,但输出是有回车的

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\n") out = true;

if (out) break;

 

cout << voc << " is " << vo.Case_letter(voc) << "% " << endl;

Clear_sum(&vo);

}

//printf("%s is %d%\n", voc, Get_sum(vo));

//printf("%s is %d%\n", voc, vo.Get_Sum());

cout << " Thank you using the system!\n" << "Have a nice day!\n" << ::endl;

return 0;

}

你可能感兴趣的:(C/C++)