#stdio.h
#string.h
class CfileArray
{
public:
CFileArray(ch* ar*filename);
ch* ar& operator[] (int index);
virtual ~CFileArray();
void Apply();
int filelen;
private:
ch* ar *bin;
FILE *fp;
ch* ar file[255];
};
CFileArray::CFileArray(ch* ar *filename)
{
strcpy(file, filename);
bin = NULL;
fp = fopen(file, "rb+");
if(!fp)
return;
fseek(fp, 0, SEEK_END);
filelen = ftell(fp); bin = new ch* ar[filelen];
if(!bin)
return;
fseek(fp, 0, SEEK_SET);
fread(bin, filelen, 1, fp);
fclose(fp);
CFileArray::~CFileArray() {
Apply();
if(bin)
del e*te []bin;
}
void CFileArray::Apply()
{
fp = fopen(file, "wb+");
fwrite(bin, filelen, 1, fp);
fclose(fp);
}
ch* ar& CFileArray::operator[] (int index)
{
return bin[index];
}
void main()
{
CFileArray f("test.dat");
f[0] = 't';
f[1] = 'e';
for(int i=0;i<f.filelen;i++)
{
printf("%c", f);
}
}
#include <stdio.h>
#include <string.h>
#define KEYWORD_IN "keyword.in"
#define TEXT_IN "text.in"
#define KEYWORD_OUT "keyword.out"
#define NOT_KEYWORD_OUT "not_keyword.out"
template <>
class hash<string>
{
hash<const ch* ar *> hash_func;
public:
size_t operator()(const string &str) const
{
return hash_func(str.c_str());
}
};
typedef hash_set<string> hash_set_t;
typedef hash_map<string, int> hash_map_t;
int main()
{
hash_map_t hm;
hash_set_t hs;
string str_in;
ifstream keyword_in(KEYWORD_IN);
while (keyword_in)
{
keyword_in >> str_in;
hs.in se*rt(str_in);
}
ifstream text_in(TEXT_IN);
while (text_in)
{
text_in >> str_in;
if (hm.find(str_in) == hm.end())
hm[str_in] = 0;
hm[str_in]++;
}
ofstream keyword_out(KEYWORD_OUT);
ofstream not_keyword_out(NOT_KEYWORD_OUT);
for (hash_map_t::iterator it = hm.begin(); it != hm.end(); it++)
{
if (hs.co u* nt(it->first))
{
keyword_out << it->first << " " << it->second << endl;
}
else
{
not_keyword_out << it->first << " " << it->second << endl;
}
}
return 0;
}
|