1) 下面代码有哪些错误?(台湾某公司05年12月笔试题)
设1点的坐标为(0,0),X方向向右为正,y方向向下为正,如:7的坐标为(-1,-1),2的坐标为(0,1),编程实现输入任意一坐标(x,y),输出所对应的数.(诺基亚05年笔试题).
x = y = (n - 1) / 2; //1的位置
for(int i = 0; i < len; i++)
dir = (DIRECTION)((dir + 1) % 4);
cout << "\t" << data[i][j];
//以(1,1)所在位置作为原点,向右作为x正半轴,向下作为y正半轴
int GetValue(int x, int y)
int m = max(abs(x), abs(y));
int rightBottom = m * m * 4 - 2 * m + 1;
value = rightBottom + 2 * m + m - y;
value = rightBottom + m - x;
value = rightBottom + 4 * m + x + m;
value = rightBottom - (m - y);
cout << GetValue(0 - (n - 1) / 2, i - (n - 1) / 2);
cout << "\t" << GetValue(j - (n - 1) / 2, i - (n - 1) / 2);
cerr << "Size error!" << endl;
cout << "*******************" << endl;
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2006/12/01/579505.html,如需转载请自行联系原作者