![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
#include <iostream>
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
#include <vector>
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
#include <algorithm>
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
#include <
string>
using namespace std;
// 实现输入一个数字,输出这个数字的 七段显示形式
// 每个数字用一个字节表示
//0到9的表示
char numbers[] = {0x7D, 0x28, 0x37, 0x57, 0x5A, 0x4F, 0x6F, 0x54, 0x7F, 0x5E};
void printN(
const string& n);
int main()
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
string n;
while (cin >> n)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
printN(n);
return 0;
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
bool getBit(
char number,
char c)
//七段显示的该段是否显示
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
return static_cast<
bool>(number & c);
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
void printN(
const string& n)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
vector<
int> v;
for (size_t i = 0; i < n.length(); ++i)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
v.push_back(n[i]-'0');
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
for ( i = 0; i < v.size(); ++i)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
if (getBit(numbers[v[i]], 4))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" _ ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout << endl;
for ( i = 0; i < v.size(); ++i)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
if (getBit(numbers[v[i]], 8))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"|";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
if (getBit(numbers[v[i]], 2))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"_";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
if (getBit(numbers[v[i]], 16))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"|";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout << endl;
for ( i = 0; i < v.size(); ++i)
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
if (getBit(numbers[v[i]], 32))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"|";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
if (getBit(numbers[v[i]], 1))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"_";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
if (getBit(numbers[v[i]], 64))
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
"|";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
else
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
{
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout <<
" ";
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
cout << endl;
![C语言七段显示_休闲](https://s2.51cto.com/images/editer/InBlock.gif)
}