锁定老帖子 主题:月薪16000的一道笔试题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (16)
|
|
---|---|
作者 | 正文 |
发表时间:2011-10-25
c的代码.
|
|
返回顶楼 | |
发表时间:2011-10-25
ansjsun 写道 thanq 写道 function f( v ){
var t = 0 ,t1=-1; for(;t<=v;){ if(t==v){ return t1 }else{ t++ ;t1++; } } } 你干嘛不写 function(x){ t1=-1; return x+t1 ; } 我也写了,这个让我倒抽一口凉气 |
|
返回顶楼 | |
发表时间:2011-10-25
泰山宏图 写道 ansjsun 写道 thanq 写道 function f( v ){
var t = 0 ,t1=-1; for(;t<=v;){ if(t==v){ return t1 }else{ t++ ;t1++; } } } 你干嘛不写 function(x){ t1=-1; return x+t1 ; } 我也写了,这个让我倒抽一口凉气 +也是不能用的,只能用++ ,没太明白这个问题到底要考什么呢? 只有++循环如何退出? |
|
返回顶楼 | |
发表时间:2011-10-25
hailiang0901 写道 为什么要加上月薪16000呢?哎....
加上之后就会有很多人来回复,帮他解答问题。 |
|
返回顶楼 | |
发表时间:2011-10-25
你个肺啊~
你们都是怎么想的?不让用- 明显是要来取反了做+了 public static int f(int x){ return ~x+x+x; } |
|
返回顶楼 | |
发表时间:2011-10-25
jiewo 写道 你个肺啊~
你们都是怎么想的?不让用- 明显是要来取反了做+了 public static int f(int x){ return ~x+x+x; } 人家不是不让用"~"和"+"么 |
|
返回顶楼 | |
发表时间:2011-10-25
最后修改:2011-10-25
这题Java表示压力很大,因为不能用比较运算符阿,C/C++就比较简单了
int f(int x) { for(int i = 0; ++i; ) { x++; } return x; } 期待Java高手给个答案 好像这个方法别人早就给出了,我out了 |
|
返回顶楼 | |
发表时间:2011-10-25
raojl 写道 unsigned char x = 6,b = 1;
for (int i = x ; i ; ++i) b++; x = 0; for (i = b; i ; i++ )x ++; printf("x:%d\n",x); int x = 6,b = 1; for (int i = x ; i ; ++i) b++; //拿到 逆数+1 x = 0; for (i = b; i ; i++ )x ++;//整形最大值 - ( 逆数+1) = ? printf("x:%d\n",x); |
|
返回顶楼 | |
发表时间:2011-10-26
linux-common:~/gang # vi x-1.c
#include <stdio.h> int main() { int x; int i, j; scanf("%d",&x); for(i=0; x; i++) { x++; } i++; for(j=0; i; j++) { i++; } printf("x-1=%d\n", j); } ~ ~ :sh linux-common:~/gang # gcc x-1.c linux-common:~/gang # ./a.out 1 x-1=0 linux-common:~/gang # ./a.out 65 x-1=64 linux-common:~/gang # ./a.out 0 x-1=-1 linux-common:~/gang # ./a.out -11 x-1=-12 linux-common:~/gang # |
|
返回顶楼 | |
发表时间:2011-10-26
最后修改:2011-10-26
public class Test16000 { /** * 请仅使用变量声明,赋值,++,及从0开始的for循环实现一个函数f(x), * 在x为不小于1的整数类型的情况下,使其返回值等于x-1. */ public static void main(String[] args) { System.out.println(f(100)); System.out.println(Integer.MAX_VALUE+3); System.out.println(f(Integer.MAX_VALUE+3)); } public static int f(int x) { int j=0; if(x<1) {//当传入的数小于1时排除,大于Integer.MAX_VALUE时,数据溢出会变成负数,也被排除 System.out.println("Sorry,you input number is not meet the need ,x must int type and x >=1"); } else { for(int i=0;++i<x;) { j++; } } return j; } } |
|
返回顶楼 | |