Пример #1
0
bool
tresultfile::open()
{
    if( m_mode == "r" && m_input == NULL && m_col_names.size( ) == 0 )
    {
        m_input = new std::ifstream( m_path.c_str( ) );
        std::string line;
        if( !std::getline( *m_input, line ) )
        {
            return false;
        }

        std::stringstream ss_line( line );
        std::string snp1, snp2;
        ss_line >> snp1 >> snp2;
        if( snp1 != "snp1" || snp2 != "snp2" )
        {
            delete m_input;
            m_input = NULL;
            return false;
        }

        std::string field;
        while( ss_line >> field )
        {
            m_col_names.push_back( field );
        }

        return true;

    }
Пример #2
0
int main(){

	std::string line;
	int input;
	while( std::getline(std::cin, line)){

		// Convert the line to a number
		std::stringstream ss_line(line);
		if( ! (ss_line >> input) ){
			std::cout << "Hey! You call '" << line << "' an integer?\n";
		}

		// Find the left 'edge' of the integer (the left-most `1`)
		// (uh-oh potential endian-ness problem)
		int left = 99;
		int mask;
		int i;
		for( i=32; i>0; i-=1 ){
			mask = 1 << (i-1);
			if( ((mask & input) == mask) && left == 99 ){
				left = i-1;
				break;
			}
		}
		
		// Reverse all of the bits from the left edge to 0
		int output = 0;
		for( i=0; i<=left; i+=1 ){
			mask = 1 << i;
			output |= ((mask & input) == mask) << (left - i);
		}
		
		std::cout << output << std::endl;
	}
	

	return 0;
}