打印

ソフトウェア開発問題集

引用:
原帖由 2to_ot2 于 2008-6-19 16:45 发表


之前我笔算也是这么算的。 跟你错的一样一样的
要不是哥儿俩呢。

TOP

复制内容到剪贴板
代码:
#!/bin/sh
fh="test.txt"
fh2="result.txt"
`rm -rf ${fh}`
`rm -rf ${fh2}`
`touch ${fh}`
`touch ${fh2}`

i=1
while [ ${i} -le 500 ];
do
        `echo ${i} >> ${fh}`
        i=`expr ${i} + 1`
done

`grep -e '^[0-3|5-8]\{0,1\}[0-3|5-8]\{0,2\}$' ${fh}  > ${fh2}`
count=`sed -n -e "125,125p" "${fh2}"`
echo ${count}
`rm -rf ${fh}`
`rm -rf ${fh2}`

i=111
while [ ${i} -le 666 ];
do
        `echo ${i} >> ${fh}`
        i=`expr ${i} + 1`
done
`grep -e '^[1-6]\{3\}$' ${fh} > ${fh2}`
count=`grep -n 523 "${fh2}" | cut -f 1 -d :`
count=`expr ${count} - 1`
echo ${count}
`rm -rf ${fh}`
`rm -rf ${fh2}`
shell 版

[ 本帖最后由 2to_ot2 于 2008-6-19 18:06 编辑 ]

TOP

我去写个java版,呵呵
信为人之本

TOP

算法说明:
房间号可理解为8进制,只不过是0,1,2,3,5,6,7,8
所以转化为八进制后将4--7的数字递增1。
复制内容到剪贴板
代码:
package test;

public class CreatingRoomNO {

        /**
         * This Class is to format the hospital room No.
         * @param args
         */
        public static void main(String[] args) {
                int roomNum;
                try {
                        //get input
                        System.out.println("Please input the quantity of rooms:\n");
                        byte[] buff = new byte[10];
                        System.in.read(buff);
                        //format to number
                        roomNum = Integer.valueOf(new String(buff).trim());
                       
                        //decimal to octal                       
                        String roomNumString = Integer.toOctalString(roomNum);
                       
                        //check if overbrim
                        roomNum = Integer.valueOf(roomNumString);
                        if(roomNum>500){
                                System.out.println("Too many!!");
                        }
                       
                        //format the special octal of hospital
                        for (int i = 7; i >=4; i--) {
                                roomNumString = roomNumString.replace(String.valueOf(i), String.valueOf(i+1));
                        }
                       
                        //print the result
                        System.out.println("No. is " +roomNumString);
                }catch (NumberFormatException e){
                        System.out.println("Check the input unless you want to be fired!");
                }catch (Exception e) {
                        System.out.println("Oh my god ,no way");
                }               
        }
}
信为人之本

TOP

引用:
原帖由 admin 于 2008-6-19 17:55 发表
我去写个java版,呵呵
一定要写出面向对象的。

TOP

引用:
原帖由 2to_ot2 于 2008-6-19 18:08 发表


一定要写出面向对象的。
这个,这个…………
信为人之本

TOP

回复 26# 的帖子

现在,java我都看不懂

TOP

引用:
原帖由 2to_ot2 于 2008-6-19 18:16 发表
现在,java我都看不懂
那我比你惨,我是除了java别的看不懂了………………
信为人之本

TOP

答案 

問1 エ 186 
問2 ア 152

通过这两道题,可以看出大家各怀宝刀,个个武艺高强,希望以后宝刀越磨越亮。

TOP

今天出2个简单的,答案下次给出。

問3 次の計算は何進法で行なわれているか。

131-45=53

ア 6  イ 7  ウ 8  エ 9


問4 アルファベットのAを10進数の0、Bを1、Cを2、…、Zを25とする26進数がある。
このとき、次の計算結果はいくらになるか。

DOG+CAT-FOX


ア A  イ B  ウ C  エ D

TOP