Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

附一个AC的代码

Posted by bill160 at 2022-05-13 04:01:38 on Problem 1102 and last updated at 2022-05-13 04:15:27
#include <iostream>
#include <string>
#include <vector>


const char* kDigits[10][5] = {
    // 0
    {
        " - ",
        "| |",
        "   ",
        "| |",
        " - ",
    },
    // 1
    {
        "   ",
        "  |",
        "   ",
        "  |",
        "   ",
    },
    // 2
    {
        " - ",
        "  |",
        " - ",
        "|  ",
        " - ",
    },
    // 3
    {
        " - ",
        "  |",
        " - ",
        "  |",
        " - ",
    },
    // 4
    {

        "   ",
        "| |",
        " - ",
        "  |",
        "   ",
    },
    // 5
    {
        " - ",
        "|  ",
        " - ",
        "  |",
        " - ",
    },
    // 6
    {
        " - ",
        "|  ",
        " - ",
        "| |",
        " - ",
    },
    // 7
    {
        " - ",
        "  |",
        "   ",
        "  |",
        "   ",
    },
    // 8
    {
        " - ",
        "| |",
        " - ",
        "| |",
        " - ",
    },
    // 9
    {
        " - ",
        "| |",
        " - ",
        "  |",
        " - ",
    },
};

std::string GetScaledRow(const char* row, int size) {
  std::string scaled_row = row[0] +
                           std::string(size, row[1]) +
                           row[2];
   return scaled_row;
}

std::string GetRowForDigits(int nth_row, const std::string& digits, int size) {
  std::string ret;
  for (int i = 0; i < digits.size(); i++) {
    int digit = digits[i]- '0';
    ret += GetScaledRow(kDigits[digit][nth_row], size) + ' ';
  }
  return ret;
}

void DisplayDigits(const std::string& digits, int size) {
  // Prints the top row
  std::cout << GetRowForDigits(0, digits, size) << std::endl;

  // Prints the upper rows
  for (int i = 0; i < size; i++) {
    std::cout << GetRowForDigits(1, digits, size) << std::endl;
  }

  // Prints the middle row
  std::cout << GetRowForDigits(2, digits, size) << std::endl;

  // Prints the lower rows
  for (int i = 0; i < size; i++) {
    std::cout << GetRowForDigits(3, digits, size) << std::endl;
  }

  // Prints the bottom row
  std::cout << GetRowForDigits(4, digits, size) << std::endl;
}

int main() {

  int size;
  std::string numbers_to_display;

  while(std::cin>>size && size != 0) {
    std::cin >> numbers_to_display;
    DisplayDigits(numbers_to_display, size);
    std::cout << std::endl;
  }
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator