카타 8급 Simple Fun #1: Seats in Theater

1 C[ | ]

int seats_in_theater(int n_cols, int n_rows, int col, int row) {
  return (n_cols+1-col)*(n_rows-row);
}

2 C++[ | ]

int seats_in_theater(int total_col, int total_row, int col, int row) {
  return (total_col+1-col)*(total_row-row);
}

3 Kotlin[ | ]

fun seatsInTheater(nCols: Int, nRows: Int, col: Int, row: Int) = (nCols - col + 1) * (nRows - row)
fun seatsInTheater(nCols: Int, nRows: Int, col: Int, row: Int): Int {
  val columns = nCols - col +1
  val rows = nRows - row 
  return columns * rows 
}

4 PHP[ | ]

function seatsInTheater($nCols, $nRows, $col, $row) {
  return ($nCols+1-$col)*($nRows-$row);
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}