主题:
牛客网的:字符串分割
问题事象:
不通过
您的代码已保存
答案错误:您提交的程序没有通过所有的测试用例
case通过率为0.00%
用例:
urivthvtlqqerctlxmjvkgvfclaaduwmaadedpadanl
batkqdhjnrwtsmzidswdnenqpsblsszldyttytrgenaizwehntqiaaufble
对应输出应该为:
urivthvt
lqqerctl
xmjvkgvf
claaduwm
aadedpad
anl00000
batkqdhj
nrwtsmzi
dswdnenq
psblsszl
dyttytrg
enaizweh
ntqiaauf
ble00000
你的输出为:
urivthvt
lqqerctl
xmjvkgvf
claaduwm
aadedpad
anl000000
而在eclipse中执行本测试用例
返回结果为:
urivthvt
lqqerctl
xmjvkgvf
claaduwm
aadedpad
anl00000
batkqdhj
nrwtsmzi
dswdnenq
psblsszl
dyttytrg
enaizweh
ntqiaauf
ble00000
与上记牛客网中记载的预期值一致
实现代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] s = new String[100]; s[0] = in.nextLine(); s[1] = in.nextLine(); List<String> arrayList = new ArrayList<>(); countStr(s[0], arrayList); countStr(s[1], arrayList); for(String value:arrayList){ System.out.println(value); } } public static List<String> countStr(String inputStr, List<String> arrayList) { if (inputStr.length() <= 8) { if (inputStr.length() == 8) { arrayList.add(inputStr); } else { int length = inputStr.length(); for (int i = length; i <= 8; i++) { inputStr = inputStr.concat("0"); } arrayList.add(inputStr); } return arrayList; } else { arrayList.add(inputStr.substring(0, 8)); inputStr = inputStr.substring(8); return countStr(inputStr, arrayList); } } }
```
全部评论
(3) 回帖