# Cow Multiplication

### From Progteam

Sorter: | Eric |
---|---|

Source: | USACO 2008 February Bronze |

Link: | http://acm.pku.edu.cn/JudgeOnline/problem?id=3673 |

**Judging Olympiad** is problem number 3673 on the Peking University ACM site.

## Contents |

## Problem Information

Problem Name: Cow Multiplication

Problem Number on PKU: 3673

Synopsis: A pairwise multiplication of two integers.

## Solver Information

Solver: Eric Hong

Date: September 21, 2008

## Trivia

None.

## General Strategy

- Using Scanner, take the input.

- Add the products of digits in two String using nested for loops.

## Solution

import java.util.*; public class Main { public static Scanner in; public static void main(String[] args) { in = new Scanner(System.in); doStuff(); } public static void doStuff() { String s = in.next(); String t = in.next(); solve(s, t); } public static void solve(String s, String t) { int len1 = s.length(); int len2 = t.length(); int sum = 0; for (int i = 0; i < len1; i++) { int num1 = s.charAt(i) - '0'; for (int j = 0; j <len2; j++) { int num2 = t.charAt(j) - '0'; sum += (num1 * num2); } } System.out.println(sum); } }

## Additional Remarks

Memory: 2064K

Time: 1641MS

This solution may not be as efficient as it can be.