powerwind 发表于 2006-5-31 19:03

这道题,大家做做看

要求程序打印出......
规律如下:

3
13//1个3
1113//1个1,1个3
3113//3个1,1个3
132113//1个3,2个1,1个3,
1113122113//1个1,1个3,1个2,2个1,1个3
311311222113

iptton 发表于 2006-5-31 19:45

找规律????

把题目帖全呀。。。

wool王 发表于 2006-5-31 21:09

看不明白规律。。。

powerwind 发表于 2006-5-31 22:43

我也没有原题,除了第一行,每行都是根据上一行的数字读x个y,然后输出X,Y
3
13//1个3就输出1和3
1113//3个1(输出3和1)1个3(输出1和3)加起来就是31 13

iptton 发表于 2006-5-31 23:25

链表。。。。

遍历输出。。。插入。。。遍历输出。。。插入。。。遍历输出。。。

[ 本帖最后由 iptton 于 2006-5-31 23:28 编辑 ]

powerwind 发表于 2006-5-31 23:47

我用JAVA做了一个,大概测试一下,没错.
大家用其它语言其它方法试试看.

public class Test
{
        static int x=0;
        static void f(String s)
        {
                if(x++>10)return;
                int len=s.length();
                int index=0;
                int count=0;
                StringBuffer buffer=new StringBuffer();
                for(int i=0;i<len;i++)
                {
                        if(i>=index)
                        {
                                for(int j=index;j<len;j++)
                                {
                                        ++index;
                                        ++count;
                                        if(j+1>=len||s.charAt(j)!=s.charAt(j+1))break;
                                }
                                if(count>0)
                                {
                                        buffer.append(count);
                                        buffer.append(s.charAt(index-1));
                                }
                        }
                        count=0;
                }
                System.out.println(buffer);
                f(buffer.toString());

        }
        public static void main(String []args)
        {
                f("3");
        }
}

iptton 发表于 2006-6-1 13:45

没什么意思好像……

纯粹是练习……
页: [1]
查看完整版本: 这道题,大家做做看