错误答案卡蒂斯问题“一只眼睛一个i”

dldeef67  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(192)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

5天前关门了。
改进这个问题
我不断地从kattis那里得到错误的答案,尽管这个程序通过了我所有的测试。如果有人能运行我的代码,找出我哪里做错了,我会很感激的。谢谢您!
下面是问题的链接:“我为一只眼睛”
这是我的密码:

import java.util.Scanner;

public class Eye {
    String[] c = {"@","&","1", "1","2", "2", "2", "4", "4", "b", "b", "b", "c", "c", "i","o", "o", "r","u","y"};
    String[] sub = {"at", "and","one","won","too", "to", "two","for", "four", "bea", "bee", "be", "sea", "see","eye", "oh", "owe", "are","you","why"};
    public boolean check(String s) {
        for(int j = 0; j < 20; j++) {
            if(s.toLowerCase().equals(sub[j])) {
                return true;
            }
        }
        return false;
    }
    public boolean checki(String s) {
        for(int j = 0; j < 20; j++) {
            if(s.toLowerCase().contains(sub[j])) {
                return true;
            }
        }
        return false;
    }
    public String title(String s) {
        StringBuffer temp = new StringBuffer(s.length());
        String[] temp2 = s.split("");
        for(int k = 0; k < s.length(); k++) {
            if(k == 0) {
                temp.append(temp2[k].toUpperCase());
            } else {
                temp.append(temp2[k]);
            }
        }
        return temp.toString();
    }
    public boolean isUpperCase(String s) {
        if(s.codePointAt(0) > 64 && s.codePointAt(0) < 92) {
            return true;
        }
        return false;
    }
    public String[] have(String s) {
        String[] sa = s.split("");
        String oc = "";
        for(int i = 0; i < s.length(); i++) {
            String t = "";
            for(int j = i; j < s.length(); j++) {
                t += sa[j];
                for(int k = 0; k < 20; k++) {
                    if(t.toLowerCase().equals(sub[k])) {
                        oc += t + " ";
                    }
                }
            }
        }
        return oc.split(" ");
    }
    public String replace(String s) {
        String[] sA = s.split(" ");
        String result = "";
        for(int i = 0; i < sA.length; i++) {
            if(check(sA[i])) {
                for(int j = 0; j < 20; j++) {
                    if(sA[i].toLowerCase().equals(sub[j])) {
                        if(j > 8 && isUpperCase(sA[i])) {
                            result += title(c[j]);
                            break;
                        } else {
                            result += c[j];
                            break;
                        }

                    }
                }
            } else if(checki(sA[i])) {
                for(int j = 0; j < 20; j++) {
                    if(sA[i].toLowerCase().contains(sub[j])) {
                        if(j > 8) {
                            String[] hA = have(sA[i]);
                            for (String b : hA) {
                                if(b.toLowerCase().equals(sub[j]) && isUpperCase(b)) {
                                    sA[i] = sA[i].replaceAll(title(sub[j]), title(c[j]));
                                } else {
                                    sA[i] = sA[i].replaceAll(sub[j], c[j]);
                                }
                            }   
                        } else {
                            if(isUpperCase(sA[i])) {
                                sA[i] = title(sA[i].toLowerCase().replace(sub[j], c[j]));
                            } else {
                                sA[i] = sA[i].toLowerCase().replace(sub[j], c[j]);
                            }   
                        }

                    }
                }
                result += sA[i];
            } else {
                result += sA[i];
            }

            if(i < (sA.length - 1)) {
                result += " ";
            }
        }
        return result;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String[] sen = new String[n];
        for(int i = 0; i < n; i++) {
            sen[i] = in.nextLine();
        }
        in.close();
        Eye e = new Eye();
        for(int i = 0; i < n; i++) {
            System.out.println(e.replace(sen[i]));
        }
    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题