#include<iostream>
#include<fstream>
#include<string>
#include<string.h>
#include<sstream>

using namespace std;

string int2str(int &);

int main(void)
{
    char* ptrInName = NULL;
    ptrInName = new char[500];
    char* ptrOutName = NULL;
    ptrOutName = new char[500];
    
	int x = 0;
	   
    cout << "Input:" << endl;
    cin >> ptrInName ;
    
    cout << "\n" << "每幾列取一列:" << endl;
	cin >> x;
	
	string y;
	y = int2str(x);
			
    strcpy(ptrOutName, ptrInName);
    
    char strtoChar[2];
    strcpy(strtoChar, y.c_str());
    strcat(strtoChar, ".xyz");
    char total[] = "-";
    strcat(total, strtoChar); 
    

    char *pch = NULL;
    pch = strstr(ptrOutName,".xyz"); 
    
    int num = strlen(total);

    strncpy (pch,total,num);
        
    cout << "\n" << "Ouput:" << "\n" << ptrOutName << endl; //
	
    char* file1 = ptrInName;     
    char* file2 = ptrOutName;
    ifstream inFile1( file1 );   
    ofstream outFile( file2 );
	
	string ptrInNametoString;
    ptrInNametoString.assign(ptrInName); 
    
	ifstream ipfile;
    char text;    
	 	   
    ipfile.open(ptrInName);
    int aa = 0;
    while (ipfile.get(text))
    {
        if (text=='\n')
        {
        	aa++;
        	if ( (aa%x) == 0)
        	{   
   		    	outFile << "1\n";
			}
		}
             
    } 

    inFile1.close();
    outFile.close();

    system("pause");
	return 0;
}

string int2str(int &i) 
{
	string s;
	stringstream ss(s);
	ss << i;
	
	return ss.str();
}