注意行数是从1而不是0开始标号的就行了:
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int[] v = new int[26];
String[] str = sc.nextLine().split(" ");
for(int i = 0; i < 26; ++i) v[i] = Integer.parseInt(str[i]);
String s = sc.nextLine();
int m = 1, n = 0;
for(int i = 0; i < s.length(); ++i){
if(n + v[s.charAt(i) - 'a'] > 100){ //如果写上当前字母超出100,就换行
m++;
n = v[s.charAt(i) - 'a'];
}else n += v[s.charAt(i) - 'a']; //如果写上当前字母不够100,就继续写
}
System.out.print(m);
System.out.print(" ");
System.out.print(n);
}
}
京公网安备 11010502036488号