26个英文字母对应数字的奇妙意义
来源:互联网 发布:房卡斗地主源码 编辑:程序博客网 时间:2024/05/01 12:22
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 Zthus: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 26so: 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 <iostream>#include <string>#include <map>#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;}
阅读全文
0 0
- 26个英文字母对应数字的奇妙意义
- 算法-输出英文字母对应的数字
- 26个英文字母大小写及对应的音标
- 由数字、26个英文字母或者下划线组成的字符串:
- 奇妙的数字--蓝桥杯
- 2015 奇妙的数字
- 奇妙的数字
- 奇妙的数字
- 奇妙的数字
- 奇妙的数字
- 奇妙的数字
- 奇妙的数字
- 1.由数字、26个英文字母或者下划线组成的字符串:
- 由数字、26个英文字母、下划线或汉字的正则表达式
- 由数字、26个英文字母、下划线或汉字的正则表达式
- 由数字、26个英文字母、下划线或汉字的正则表达式
- 由数字、26个英文字母、下划线或汉字的正则表达式
- 由数字、26个英文字母、下划线或汉字的正则表达式
- hadoop-3.0.0-beta1运维手册(011):HDFS Erasure Coding纠删码使用
- Qt Creator 自动补齐函数参数问题
- EasyUI datagrid可编辑行
- (Blue) Taxi Destination and Trip Time Prediction from Partial Trajectories (阅读笔记)
- Cesium 三维飞行DEMO
- 26个英文字母对应数字的奇妙意义
- 短链服务架构实践
- 优酷、腾讯视频播放器插件
- FreeBSD简介
- 主成分分析
- Mongodb启动失败问题解决
- android+测试理论基础
- Mysql 主从同步 5.6版本配置方法
- Hanoi塔问题分析