一道简单的程序题
前言:
今天搜flood filling 算法的时候,搜到了USACO(美国计算机奥林匹克),然后注册了个帐号。做了一个题目。题目很简单,摘抄在下面了。
关键是我的表现。汗ing,竟然提交了四遍才做对。首先,编译器给了个for循环的warning,楞没看出来错哪儿了!
for(i=0;i++;i<5)
唉!没看出来啊!!!原来把自加和条件弄反了。话说,这还不是第一次犯这种低级错误了,真是蠢啊!!!
以后要记住: for(i=0;i<5;i++)。
很开心地改完后,发现又错了。这次是两个初值应赋为零的变量没赋零。改了之后,又错!!!我的天哪,我开始怀疑我的智商了!!!然后发现,题目看错了,字符串中的元素应该相乘,我写成相加了。然后,又错!!!这次是刚刚初值赋零的地方应该改成赋一了,应为改成乘法了嘛!!!
如此改了四遍,终于对了。汗!!!
华罗庚先生有一句话,叫“小敌不侮”,是说平时做点练练手,增长增长经验是有必要的。有的东西,你看着简单,做起来才发现自己有这样那样的坏毛病、或是不清楚。这时候改了,以后遇见大敌的时候才不至于因为低级错误,郁闷终生啊!!!
综上,还是那句话“你从此改悔了吧!!!”
Your Ride Is Here
It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.
Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the group "USACO" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that "a mod b" is the remainder left over after dividing a by b; 34 mod 10 is 4.)
Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing "GO" if they match and "STAY" if not. The names of the groups and the comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.
我的source code
答案的 source code
立此篇,警自己
浙公网安备 33010602011771号