花了2个多小时终于完成了。
Note(int to string):e.g:
  ostringstream ss;
  ss << mappedCounterArray[i];
  string str = ss.str();
 #include <iostream>
#include <iostream>
 #include <string>
#include <string>
 #include <fstream>
#include <fstream>
 #include   <sstream>
#include   <sstream>  
 using namespace std;
using namespace std;

 typedef bool BOOL;
typedef bool BOOL;
 const int MAX_OF_LINE = 100;
const int MAX_OF_LINE = 100;
 const int mappedCounterArray[]=
const int mappedCounterArray[]=


 {
{
 2605, 2606, 2618, 2619,
    2605, 2606, 2618, 2619,
 2609, 2610, 2622, 2623,
    2609, 2610, 2622, 2623,
 2612, 2624, 2651, 2663,
    2612, 2624, 2651, 2663,
 2613, 2625, 2652, 2664,
    2613, 2625, 2652, 2664,
 1627, 1628,
    1627, 1628,
 1623, 1624, 1625, 1626,
    1623, 1624, 1625, 1626,
 48, 49, 50, 51, 52, 54, 55, 56, 1326, 1327, 1328, 1329,
    48, 49, 50, 51, 52, 54, 55, 56, 1326, 1327, 1328, 1329,
 53,
    53,
 564, 565,
    564, 565,
 588, 589,
    588, 589,
 592, 593, 594, 595,
    592, 593, 594, 595,
 596, 597,
    596, 597,
 1616, 1617, 1618, 1619, 1621, 1659, 1660,
    1616, 1617, 1618, 1619, 1621, 1659, 1660,
 1620, 1657, 1662, 1663, 1664, 1665,
    1620, 1657, 1662, 1663, 1664, 1665,
 1630, 1631, 1635, 1649, 1650, 1651, 1652,
    1630, 1631, 1635, 1649, 1650, 1651, 1652,
 1634, 1653, 1654, 1655,
    1634, 1653, 1654, 1655,
 1647, 1648,
    1647, 1648,
 1666,
    1666,
 1667,
    1667,
 1668, 1669, 1672, 1673, 1674, 1675,
    1668, 1669, 1672, 1673, 1674, 1675,
 1670, 1671, 1676, 1677, 1678, 1679,
    1670, 1671, 1676, 1677, 1678, 1679,
 1163, 1164,
    1163, 1164,
 1711, 1712, 1713, 1714,
    1711, 1712, 1713, 1714,
 1715, 1716, 1717, 1718, 1743, 1744, 1745, 1746,
    1715, 1716, 1717, 1718, 1743, 1744, 1745, 1746,
 1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727,
    1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727,
 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742,
    1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742,
 590, 591,
    590, 591,
 2728
    2728
 };
};

 BOOL isMappedCounter(const string& counterIDStr)
BOOL isMappedCounter(const string& counterIDStr)


 {
{
 int size = sizeof(mappedCounterArray)/sizeof(int);
    int size = sizeof(mappedCounterArray)/sizeof(int);
 int i=0;
    int i=0;
 while (i<size)
    while (i<size)

 
     {
{
 ostringstream ss;
        ostringstream ss;
 ss << mappedCounterArray[i];
        ss << mappedCounterArray[i];
 string str = ss.str();
        string str = ss.str();
 str += " ";
        str += " ";
 str = " " + str;
        str = " " + str;

 if (counterIDStr.find(str)<counterIDStr.length())
        if (counterIDStr.find(str)<counterIDStr.length())
 return true;
            return true;
 i++;
        i++;
 }
    }
 return false;
    return false;
 }
}

 void setFile(void)
void setFile(void)


 {
{
 ifstream in_file;
    ifstream in_file;
 in_file.open("./abc.txt");
    in_file.open("./abc.txt");

 ofstream out_file;
    ofstream out_file;
 out_file.open("outFile.txt");
    out_file.open("outFile.txt");

 char ptr[MAX_OF_LINE];
    char ptr[MAX_OF_LINE];
 for (int i=0; i<MAX_OF_LINE;i++)
    for (int i=0; i<MAX_OF_LINE;i++)
 ptr[i]='\0';
        ptr[i]='\0';
 while(in_file.getline(ptr,MAX_OF_LINE))
    while(in_file.getline(ptr,MAX_OF_LINE))

 
     {
{
 string str=ptr;
        string str=ptr;
 if ((str.find("**id = ")<str.size()) && (!isMappedCounter(str)) )
        if ((str.find("**id = ")<str.size()) && (!isMappedCounter(str)) )
 str=str.substr(0,str.find("**id = "));
            str=str.substr(0,str.find("**id = "));
 out_file << str << endl;
        out_file << str << endl;
 cout << str << endl;
        cout << str << endl;
 }
    }
 in_file.close();
    in_file.close();
 out_file.close();
    out_file.close();
 }
}

 BOOL isSpaceOrTab(const string& str)
BOOL isSpaceOrTab(const string& str)


 {
{
 char ch_space = ' ';
    char ch_space = ' ';
 char ch_tab = '\b';
    char ch_tab = '\b';
 size_t i=0;
    size_t i=0;
 while (i<str.length())
    while (i<str.length())

 
     {
{
 if ((str[i] != ch_space) && (str[i] != ch_tab))
        if ((str[i] != ch_space) && (str[i] != ch_tab))
 return false;
            return false;
 i++;
        i++;
 }
    }
 return true;
    return true;
 }
}

 void removeSpace(void)
void removeSpace(void)


 {
{
 ifstream in_file;
    ifstream in_file;
 in_file.open("./outFile.txt");
    in_file.open("./outFile.txt");

 ofstream out_file;
    ofstream out_file;
 out_file.open("outFileWithNoSpace.txt");
    out_file.open("outFileWithNoSpace.txt");

 char ptr[MAX_OF_LINE];
    char ptr[MAX_OF_LINE];
 for (int i=0; i<MAX_OF_LINE;i++)
    for (int i=0; i<MAX_OF_LINE;i++)
 ptr[i]='\0';
        ptr[i]='\0';
 while(in_file.getline(ptr,MAX_OF_LINE))
    while(in_file.getline(ptr,MAX_OF_LINE))

 
     {
{
 string str=ptr;
        string str=ptr;
 out_file << str << endl;
        out_file << str << endl;
 cout << str << endl;
        cout << str << endl;
 
        
 while (isSpaceOrTab(str))
        while (isSpaceOrTab(str))

 
         {
{
 in_file.getline(ptr,MAX_OF_LINE);
            in_file.getline(ptr,MAX_OF_LINE);
 str = ptr;
            str = ptr;
 if (isSpaceOrTab(str))
            if (isSpaceOrTab(str))
 continue;
                continue;
 out_file << str << endl;
            out_file << str << endl;
 cout << str << endl;
            cout << str << endl;
 break;
            break;
 }
        }
 }
    }
 in_file.close();
    in_file.close();
 out_file.close();
    out_file.close();
 }
}

 int main()
int main()


 {
{
 setFile();
    setFile();
 removeSpace();
    removeSpace();
 system("pause");
    system("pause");
 return 0;
    return 0;
 }
}posted on 2009-02-18 23:53 
Jiggy.Stone 阅读(284) 
评论(0)  编辑 收藏 引用  所属分类: 
C++ Zealot!