/*很不好意思!这个程序肯定有很多的不规范的地方!因为有很多的warning,我是个初学者,请大家不要见笑。*/
#include "stdafx.h"
#include <vector>
#include <string>
#include <map>
#include <iostream>
using namespace std;
//get_name():得到txt文件中的汉字;
//get_val():得到txt文件中汉字后面的数字;
//result_map():从get_val中得到的数字的总和;
//map_template():get_name中得到的汉字是map中的key,get_val中得到的数字是map中的value;
//主程序中的infile可以是:c:\\work\\try.txt
class try_map_template{
public:
try_map_template(string &add_template);
string add_template() {return _add_template;}
map<string,float> map_template();
float result_map() ;
vector<string> get_name();
vector<float> get_val();
ostream& print(ostream &os);
private:
string _add_template;
map<string,float> _a_map;
float _result_map;
vector<string> _val_name;
vector<float> _get_val;
};inline try_map_template::try_map_template(string &add_template):
_add_template(add_template),_get_val(0),_val_name(0){}inline vector<string> try_map_template::get_name()
{
string str;
char ch1[10],ch2[10];
FILE *ofile;
ofile=fopen("_add_templat","r");
while(!feof(ofile))
{
int count=0;
if(!fgets(ch1,30,ofile))
   break;
        while(ch1[count]!='\n')
count++;
count++;
for(int ix=0;ix<count;++ix)
{
if(ch1[ix]>=-1)
break;
else
ch2[ix]=ch1[ix];
}
ch2[ix+1]='\0';
str=ch2;
      _val_name.push_back(str);
}
return _val_name;
}inline vector<float> try_map_template::get_val()
{
float fl;
char ch1[10],ch2[10];
FILE *ofile;
ofile=fopen("_add_templat","r");
while(!feof(ofile))
{
int count=0;
if(!fgets(ch1,30,ofile))
break;
while(ch1[count]!='\0')
count++;
count++;
for(int ix=0;ix<count;++ix)
{
int i=0;
if(ch1[ix]=='\\')
{
++ix;
ch2[i]=ch1[ix];
i++;
}
ch2[i]='\0';
fl=atof(ch2);
_get_val.push_back(fl);
}
}
return _get_val;
}
inline map<string,float> try_map_template::map_template()
{
vector<string>::iterator ch_it=_val_name.begin();
vector<float>::iterator fl_it=_get_val.begin();
int count1=0,count2=0;
for(;ch_it<_val_name.end();++ch_it)
count1++;
for(;fl_it<_get_val.end();++fl_it)
count2++;
if(count2!=count1)
cerr<<"error";
else
{
for(;ch_it<_val_name.end();++ch_it,++fl_it)
_a_map[*ch_it]=*fl_it;
}
return _a_map;
}
inline float try_map_template::result_map()
{
vector<float>::iterator it=_get_val.begin();
_result_map=*it;
for(it++;it<_get_val.end();++it)
_result_map+=*it;
return _result_map;
}
ostream& operator<<(ostream &os,try_map_template &tmp)
{
return tmp.print(os);
}
inline ostream& try_map_template::print(ostream &os)
{
vector<string>::iterator ch_it=_val_name.begin();
vector<float>::iterator fl_it=_get_val.begin();
    for(;ch_it<_val_name.end();++ch_it)
os<<*ch_it<<" ";
os<<endl;
for(;fl_it<_get_val.end();++fl_it)
os<<*fl_it<<" ";
os<<endl;
os<<_result_map<<endl;
return os;
}int main(int argc, char* argv[])
{
string infile;
cin>>infile;
try_map_template tmp(infile);
tmp.get_name();
tmp.get_val();
tmp.map_template();
cout<<tmp;
return 0;
}