一道有趣的编程题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wangsiman/article/details/50560497

题目:实现字符串拼接 replace(replace(replace(replace(relatedzoneidinfo, '501', '0'), '502', '0'), '503', '0'), '504', '0')


答案:方案一:先组装四个replace(,  + relatedzoneidinfo + 组装四个 ,‘id’,'0')    

            总结:简明易懂,需要两个for循环


           方案二:result = "relatedzoneidinfo";

                          for (i =501; i<=504;i++)

                          {

                                 result = "replace("+result+",'i', '0')";

                          }

           总结:只需要一个for循环

展开阅读全文

一道有趣

07-07

题目:假设是原始社会,有石头,2块石头互磨可以变成石刀,石刀可以去砍木头,木头被砍成木材,木材可以组成椅子,请你用oo的 思想把这些事物和他们之间的关系表达出来,但是要考虑到以后可能我会增加以下几点: "1.有可能我还想让石刀去砍椅子,把椅子砍成木材,2.可能我还想让石头增加关系,例如互相砸,互相摔,而不只是磨,也可以变 成石刀,3也许我又要多添一百种不同的事物,再多添120种不同的关系... " 也就是说我的要求可能是不断变化的,所以你要怎么样设计这个oo的模型,可以让我在实行1,2,3条的时候只做最小的修改.... rnrn原来CSDN上有这个贴子,我在他们的基础上修改了一些,TX们有没有更完美的解决方案呢?rnrn以下是我的理解:rnpackage 原始社会rnrnabstract class 抽象石头 rn abstract 相砸(另一个石头) rn abstract 相摔(另一个石头) rn abstract 相磨(另一个石头) rnrnrnabstract class 抽象石刀 extends 抽象石头 rn abstract 砍(木头)rn abstract 砍(椅子) rn rnrnclass 石头 extends 抽象石头rn 相砸(另一个石头)...... rn 相摔(另一个石头)...... rn 相磨(另一个石头)...... rn rnrnrnclass 石刀 extends 抽象石刀rn 石刀 (石头1,石头2)...... rn 砍(木头)......rn 砍(椅子)...... rnrnrnclass 木头rnrnrnclass 木材 extends 木头rn 木材(石刀,木头)rn 石刀.砍(木头);rn ......rn rn 木材(石刀,椅子)rn 石刀.砍(椅子);rn ......rn rnrnrnrnclass 椅子 extends 木材 rn 椅子 (木材1,木材2...)......rnrnrn rnrn 论坛

一道有趣的算法求助?

04-07

Mr. Moled has n column reservoirs underground, numbered from 1 to n. All of these reservoirs have a same sectional area. To connect these reservoirs, Mr. Moled digs m pipes. Each pipe connects exactly two reservoirs. And all the pipes are parallel with the ground. These pipes are so thin that they will not save any water. Now Mr. Moled will pour water into the reservoirs. You can assume the water passes through the pipes very quickly. Mr. Moled wants to know the height of the water in each reservoir at last.rnThings you should pay attention to:rn1. If water overflows sometime, the overflowed water will flow away and be lost.rn2. No two pipes have same depth. But a pipe may have same depth with one or two reservoirs which it connects.rn3. The reservoir’s sectional area is 1.rnInput (Please use standard input, and don’t read or write files.)rnThere are three integers in the first line, n, m and k.rnThe second line contains n integers, means the depth of each reservoir.rnThe next m lines each contains three integers, a, b and d. This means there is a pipe at the depth d connecting reservoir a with reservoir b.rnThe next k lines. In each line there are two integers, i and v, means Mr. Moled pours v water into the ith reservoir.rnOutput (Please use standard output, and don’t read or write files.)rnYou should output n lines and each line contains only one real number. The ith number means the volume of water in the ith reservoir. The answer should be rounded to two decimals.rnrnSample Inputrn5 4 3rn3 4 5 6 7rn1 2 3rn2 3 4rn3 4 5rn4 5 6rn3 2rn3 2rn5 7rnSample Outputrn0.20rn1.20rn2.20rn3.20rn4.20rnHintrnFor 100% cases, 0 < n <= 50, 0 < m <= 2000, 0 < k <= 100rn原题如此,我就不画蛇添足翻译了。希望大家给点思路,或提示下应该用什么算法? 论坛

没有更多推荐了,返回首页