A2: symmetric digits

  integers of symmetric digits

coplexity: O(n)


#include <iostream>
#include <vector>

using namespace std;

bool isSymetric( int x ) {
	char buff[32];
	int i=0;
	while( x != 0){
		buff[i++] = x%10;
		x/=10;
	}
	int j=0;
	i-=1;
	while( j<i) {
		if(buff[j++] != buff[i--] ) return false;
	}
	return true;
}

int main(int argc, char** argv)
{
	int x[] = {0, INT_MAX, INT_MIN, 123454321, 123453421};
	int sz = sizeof(x) / sizeof(int);
	for( int i=0; i<sz; i++) {
		cout<<isSymetric(x[i])<<endl;
	}
}


posted @ 2013-01-23 06:28  西施豆腐渣  阅读(108)  评论(0编辑  收藏  举报