| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
附一个AC的代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator