import java.util.ArrayList;
import java.util.Scanner;

public class Solution {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
String nextLine = scanner.nextLine();

Integer scoreRet = getScoreRet(nextLine);

System.out.println(scoreRet);

}

public static Integer getScoreRet(String srcScoreArrStr){
if (srcScoreArrStr==null){
return -1;
}
if (srcScoreArrStr.isEmpty()){
return -1;
}

String trimSrcScoreTempArrStr = srcScoreArrStr.trim();
String[] splitSrcScoreTempArrStr = trimSrcScoreTempArrStr.split("\\s");
int length = splitSrcScoreTempArrStr.length;
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < length; i++) {
String scoreStrTemp = splitSrcScoreTempArrStr[i];
stringBuilder.append(scoreStrTemp);
}
String srcScoreArr = stringBuilder.toString();

int srcScoreArrLen=srcScoreArr.length();
for (int i = 0; i < srcScoreArrLen; i++) {
char charAt = srcScoreArr.charAt(i);
if (Character.isDigit(charAt)){
continue;
}else if (charAt=='+'){
continue;
}else if (charAt=='C'){
continue;
}else if (charAt=='D'){
continue;
}else{
return -1;
}
}

if (srcScoreArrLen>1000 || srcScoreArrLen<1){
return -1;
}

int multiPlyFac=10;
for (int i = 0; i < 4; i++) {
multiPlyFac*=10;
}
int lowDeadLineNum=-3;
lowDeadLineNum*=multiPlyFac;
int highRestricNum=3;
highRestricNum*=multiPlyFac;

for (int i = 0; i < srcScoreArrLen; i++) {
char charAt = srcScoreArr.charAt(i);
Integer integerScore = Integer.valueOf(charAt);
if (Character.isDigit(integerScore)){
if (integerScore<lowDeadLineNum){
return -1;
}
if (integerScore>highRestricNum){
return -1;
}
}
}

if (srcScoreArr.length()==1){
char srcScoreArr1 = srcScoreArr.charAt(0);
if (Character.isDigit(srcScoreArr1)){
return Integer.valueOf(srcScoreArr1);
}
if (srcScoreArr1=='+'){
return -1;
}
}


ArrayList<Integer> integerArrayList = new ArrayList<Integer>();
for (int i = 0; i < srcScoreArrLen; i++) {
char charAt = srcScoreArr.charAt(i);
Integer integerScore=0;
if (Character.isDigit(charAt)) {
integerScore = Integer.valueOf(charAt);
integerArrayList.add(integerScore);
continue;
}else {
char charAt1 = srcScoreArr.charAt(0);
if (charAt1=='+'){
integerScore=-1;
integerArrayList.add(integerScore);

continue;
}else {
if (charAt=='C'){
int indexPre=i-1;
char charAtPre = srcScoreArr.charAt(indexPre);
Integer integerScoreFactor = Integer.valueOf(charAtPre);
if (Character.isDigit(integerScoreFactor)){

integerArrayList.remove(indexPre);

continue;
}
}

if (charAt=='D'){
int indexPre=i-1;
char charAtPre = srcScoreArr.charAt(indexPre);
if (Character.isDigit(charAtPre)){
if (Character.isDigit(charAtPre)){
Integer integerScoreTemp = Integer.valueOf(charAtPre);
int scoreFactor=integerScoreTemp*2;

integerScore=scoreFactor;

integerArrayList.add(integerScore);

continue;
}
}
}

if (charAt=='+'){
int indexPre=i-1;
char charAtPre= srcScoreArr.charAt(indexPre);
if (Character.isDigit(charAtPre)){

char charAtCurr = srcScoreArr.charAt(i);
Integer integerScoreCurr = Integer.valueOf(charAtCurr);

Integer integerScoreTemp = Integer.valueOf(charAtPre);
int scoreFactor=integerScoreCurr+integerScoreTemp;

integerArrayList.add(scoreFactor);

continue;
}
}

}
}
}


int scoreRet=0;
for (Integer integer : integerArrayList) {
scoreRet+=integer;
}

return scoreRet;
}
}
posted on 2024-09-07 12:18  CoderOilStation  阅读(58)  评论(0)    收藏  举报