상세 컨텐츠

본문 제목

[백준>단계별로 풀어보기>입출력과 사칙연산>곱셈] JAVA 풀이

PROGRAMMING/백준알고리즘

by 니콜 키크드만 2020. 1. 23. 09:52

본문

public class Main { 
	public static void main(String[] args) { 
		java.util.Scanner sc = new java.util.Scanner(System.in); 

		String fstStr = sc.nextLine(); 
		String secStr = sc.nextLine(); 

		int totalValue = 0; // 마지막 총 합 
		String intFormatTotal = "1"; //  
		for(int i =0; i < secStr.length(); i++) { // 385 
			int splitIntBottom = Integer.parseInt(secStr.split("")[(secStr.length()-1) - i]); //  
			int sumValue = 0; // 연산 중의 값들 

			String intFormat = "1"; // 연산 중의 값 단위 맞추는 변수 

			if(i !=0 ) { 
				intFormatTotal += "0"; 
			} 

			for(int j = 0; j < fstStr.length(); j++) { // 472 
				if(j !=0 ) { 
					intFormat += "0"; 
				} 
				int splitIntTop = Integer.parseInt(fstStr.split("")[(fstStr.length()-1) - j]); 

				sumValue += splitIntBottom * splitIntTop * Integer.parseInt(intFormat); 
			} 

			System.out.println(sumValue); 
			totalValue += sumValue * Integer.parseInt(intFormatTotal); 
		} 
		System.out.println(totalValue); 
	} 
} 

궁금한건 댓글 주세요

알고리즘에 최선의 답은 없습니다.

반응형

관련글 더보기

댓글 영역