#include <iostream>
using namespace std;
#include <list>
#include <map>
#include <vector>
#include <fstream>
void getValue(vector<char> &vecc,vector<int> &veci)
{
// int j;
// char c[2];
char cTemp;
int iTemp;
ifstream infile1,infile2;//定义文件输出类
infile1.open("file1.txt");
infile2.open("file2.txt");
for (int i=0; i<26; i++) {
infile1>>cTemp;
vecc.push_back(cTemp);
//c[0] = cTemp;
infile2>>iTemp;
veci.push_back(iTemp);
//j = iTemp;
}
infile1.close();
infile2.close();
}
int serch(char c)
{
//int j;//记录下标
vector<char> vecc;
vector<int> veci;
getValue(vecc, veci);
map<char, int>maplive;
for (int i=0;i<vecc.size() ; i++) {
maplive.insert(pair<char, int>(vecc.at(i),veci.at(i)));
} //键值对存在map中
//补充一个空格的map
maplive.insert(pair<char, int>(' ',0));
map<char,int>::iterator l_it;
l_it = maplive.find(c);
return l_it->second;
// return ;
}
int main(int argc, const char * argv[])
{
char num[26] = {'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'};
int val[26];
for (int i=0; i<26; i++) {
val[i] = i+1;
}
//将数据存储到文件中
ofstream onfile1,onfile2;//定义输出文件(将数据写入到文件中)
onfile1.open("file1.txt");//打开一个输入文件file1用来保存26个英文字母
onfile2.open("file2.txt");//保存1-26数字
for (int i=0; i<26; i++) {
onfile1<<num[i]<<' ';
onfile2<<val[i]<<' ';
}
onfile1.close();
onfile2.close();
char f1[10];
do {
int sum=0;
char s[50];
string ss;
cout<<"请输入要计算的字符串"<<endl;
cin.getline(s, 40);
char *p = s;
int j=strlen(p);
for (int i=0; i<j; i++){
sum+=serch(s[i]);
}
cout<<s<<":"<<sum<<"%"<<endl;
cout<<"您还要继续计算吗?(Y/N)";
//cin>>f>>f;
cin.getline(f1,10);
}while('Y' == f1[0]);
cout<<"欢迎使用!谢谢!"<<endl;
return 0;
}