在VIJOS上用Java实现算法出现的问题
PHP中文网
PHP中文网 2017-04-18 10:56:13
0
1
420
  • 最后程序编译出现RUNTIME ERROR【网站提示】Runtime Error 不通过:程序运行时错误(如数组越界、被零除、运算溢出、栈溢出、无效指针等)

【问题】想必有人做过vijos这道题吧?不太清楚本人程序哪里出现了这样的问题?另本人还是小白,代码暴力破解...欢迎愿意的大神提供给更优方案哈~

【以下为题目描述】

华华通过以下方式进行分析,首先将比赛每个球的胜负列成一张表,然后分别计算在11分制和21分制下,双方的比赛结果(截至记录末尾)。
比赛规则和实际比赛规则相同, 在11分制下比分为10:11时还要继续比赛,直到分数差距达到2分;同理21分制下比分为20:21的时候也还要继续比赛。
比如现在有这么一份记录,(其中W表示华华获得一分,L表示华华对手获得一分):
WWWWWWWWWWWWWWWWWWWWWWLW
在11分制下,此时比赛的结果是华华第一局11比0获胜,第二局11比0获胜,正在进行第三局,当前比分1比1。而在21分制下,此时比赛结果是华华第一局21比0获胜,正在进行第二局,比分2比1。如果一局比赛刚开始,则此时比分为0比0。
你的程序就是要对于一系列比赛信息的输入(WL形式),输出正确的结果。
格式

【输入格式】

每个输入文件包含若干行字符串(每行至多20个字母),字符串有大写的W、L和E组成,也许中间有若干个空格。其中E表示比赛信息结束,程序应该忽略E之后的所有内容,E后面可能有干扰文字。
输出格式

输出由两部分组成,每部分有若干行,每一行对应一局比赛的比分(按比赛信息输入顺序)。其中第一部分是11分制下的结果,第二部分是21分制下的结果,两部分之间由一个空行分隔。

【样例输入1】

WWWWWWWWWWWWWWWWWWWW
WWLWE

【样例输出1】

11:0
11:0
1:1

21:0
2:1
限制

各个测试点1s

【以下为本人代码】

import java.util.Scanner; public class Main { public static void main(String[] args){ int i=0; int j=0; int a=0; int b=0; int num=0; Scanner scanner=new Scanner(System.in); String s1=scanner.nextLine(); String s2=scanner.nextLine(); String s=s1+s2; s=s.replace(" ", ""); System.out.println(s); char[] arr=s.toCharArray(); for(i=0;i2){ System.out.println(a+":"+b); a=0; b=0; } if(j==num-1){ System.out.println(a+":"+b); a=0; b=0; } } System.out.println(); for(i=0;i2){ System.out.println(a+":"+b); a=0; b=0; } if(i==num-1){ System.out.println(a+":"+b); } } } }
PHP中文网
PHP中文网

认证0级讲师

reply all (1)
Ty80

I’m not very good at Java, so I can’t read the code
However, this is a topic of the NOIP 2003 popularization group, called table tennis. Is there any algorithm for this topic? It is the violence you mentioned. In fact, it is a simulated statistical result. Okay, as for RE, you need to check the out-of-bounds problem of your array. You can download the test data of the question at the following address. You put the test data locally, test group by group, and then compare the results to see which group has The question is which group is DEBUG
http://www.jxteacher.com/ppt/...

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!