내 풀이(python)
s = input()
ix = 0
length = len(s)
total = 0
while ix <length:
if ix == 0:
total += int(s[ix])
ix += 1
continue
if (total <= 1 or int(s[ix])<=1):
total += int(s[ix])
ix += 1
else:
total *= int(s[ix])
ix += 1
print(total)
내 풀이(java)
package algorithms;
import java.util.Scanner;
public class add_or_multiply {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String solving_num = keyboard.next();
String[] str_arr = new String[solving_num.length()];
str_arr = solving_num.split("");
int container = 0;
for(int i=0; i < solving_num.length(); i++) {
if ((container == 0) || (container == 1) ||
(str_arr[i].equals("0")) || (str_arr[i].equals("1"))) {
container += Integer.parseInt(str_arr[i]);
}
else {
container *= Integer.parseInt(str_arr[i]);
}
}
System.out.println(container);
}
}
모범답안