e,刚刚改了一下,对于多少位(小于9),都能输出了,。
e,原来是c语言论坛,不过没关系,思路是一样的,。
e,原来是c语言论坛,不过没关系,思路是一样的,。
// 系统时间测试程序 #include <Windows.h> #include <conio.h> #include <Screen.h> // 全局变量 Screen screen; // 函数声明 VOID ShowDigit(const WCHAR digit, COORD location); // 程序主入口 VOID wmain(VOID) { screen.SetTitle(L"系统时间测试程序"); screen.SetTextAttribute(FOREGROUND_WHITE | BACKGROUND_BLUE).Cls(); screen.SetCursorVisible(false); screen.MoveCursor(0, screen.GetRows() - 1).WriteText(L"====按Esc键停止===="); while (!(_kbhit() && (screen.ReadKey() == screen.K_ESC))) { static WORD second(-1); SYSTEMTIME st; GetLocalTime(&st); if (st.wSecond != second) { COORD location = {5, 2}; WCHAR buffer[50]; swprintf_s(buffer, L"%4d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); for (size_t i = 0; i < wcslen(buffer); ++i) { ShowDigit(buffer[i], location); location.X += 3; } second = st.wSecond; } } screen.SetCursorVisible(true); } // 显示LED数字 VOID ShowDigit(const WCHAR digit, COORD location) { const WORD attr(screen.GetTextAttribute()); const WCHAR character = L' '; switch (digit) { case '-': screen.MoveCursor(location).SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); break; case ':': screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·'); ++location.Y; screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·'); break; case '0': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '1': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); screen.SetTextAttribute(attr).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); screen.SetTextAttribute(attr).WriteText(character); break; case '2': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '3': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '4': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '5': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '6': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '7': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character); break; case '8': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; case '9': screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); ++location.Y; screen.MoveCursor(location); screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character); screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character); break; } screen.SetTextAttribute(attr); }
#include<stdio.h> void print(int a) { const int map[10] = { 0x75557, 0x44444, 0x71747, 0x74747, 0x44755, 0x74717, 0x75717, 0x44447, 0x75757, 0x74757}; int i, j, k, len, t; for(len = t = 0; a; len++, t *= 10, t += a % 10, a /= 10); if(!len) len = 1; a = t; for(i = 0; i < 5; i++, putchar('\n')) for(t = a, k = len; k--; t /= 10) for(j = 0; j < 4; putchar((((map[t % 10] >> (i * 4)) >> j++) & 1) ? 'O' : ' ')); } int main() { int a; scanf("%d", &a); print(a); return 0; }