庞果的测试用例感觉有问题呢.自己测的好好的,到他那就失败~

米某人 2013-08-07 04:32:30
http://hero.pongo.cn/OnlineCompiler/Index?ID=75&ExamID=73


执行测试用例失败!解析这组数据出错了:<?xml version="1.0" ?><Books><Book><Name = "The C++ Programming Language" Author="Bjarne Stroustrup"></Book><Book><Name = "Effective C++" Author = "Scott Meyers"></Book></Books>
用字符串 或者读XML文件 都没问题




public static void main(String[] args) {
// String in = "<?xml version=\"1.0\" ?>" +
// "<Books><Book><Name = \"The C++ Programming Language\" Author=\"Bjarne Stroustrup\">" +
// "</Book><Book><Name = \"Effective C++\" Author = \"Scott Meyers\"></Book></Books>";
// System.out.println(in);
System.out.println(ParsingXML(Fisread("E://test.xml")));
}
public static String ParsingXML(String in){
StringBuffer sb = new StringBuffer();
String[] xmlStrs = in.split("</");
for (int i = 0; i < xmlStrs.length; i++) {
xmlStrs[i] = xmlStrs[i].replace("<", "").replace(">", "").replace("/>", "");
}
sb.append(xmlStrs[xmlStrs.length-1]+"\n");
for (int i = 0; i < xmlStrs.length-2; i++) {
sb.append(" "+xmlStrs[xmlStrs.length-2]+" "+(i+1)+"\n");
if(i==0){
xmlStrs[i] = xmlStrs[i].replace(xmlStrs[i].substring(xmlStrs[i].indexOf("?"),xmlStrs[i].lastIndexOf("?")+1), "").replace(xmlStrs[xmlStrs.length-1], "").replace(xmlStrs[xmlStrs.length-2], "");
}else{
xmlStrs[i] = xmlStrs[i].replace(xmlStrs[xmlStrs.length-i], "").replace(xmlStrs[xmlStrs.length-2], "");
}
String[] pars = xmlStrs[i].split("\"");
for (int j = 0; j < pars.length-1;) {
sb.append("\t"+pars[j].trim().replace("=", ":").replace(" ", "")+pars[j+1]+"\n");
j+=2;
}
}
return sb.toString();
}
private static String Fisread(String path){
File f = new File(path);
if(!f.exists()){
return null;
}
try {
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int)f.length()];
fis.read(b);
fis.close();
return new String(b);
} catch (IOException e) {
}
return null;
}
...全文
41 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
米某人 2013-08-07
  • 打赏
  • 举报
回复
做过好几道题了,每次都不通过~

50,533

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧