题目连接:
https://vjudge.net/problem/NBUT-1219
Time
时间限制: 1000 ms 内存限制: 131072 K
问题描述
Digital clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,”_”and” “).now given the current time, please tell us how can it be expressed by the digital clock.
输入
There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
输出
For each test case, output the time expressed by the digital clock such as Sample Output.
样例输入
1 2 5 6
2 3 4 2
样例输出
_ _ _
| _||_ |_
| |_ _||_|
_ _ _
_| _||_| _|
|_ _| ||_
这道题的意思就是输入数字然后模拟时钟,就是一个简单的给字符串赋值的过程
可以定义一个二维的数组来模拟输出的这几个数字,后来看到有大佬直接暴力定义三个一维数组来模拟,学习一波。
方法一
#include<iostream>
#include<algorithm>
using namespace std;
char s1[35]=" _ _ _ _ _ _ _ _ ";
char s2[35]=" | _| _||_||_ |_ ||_||_|| |";
char s3[35]=" ||_ _| | _||_| ||_| _||_|";
int main()
{
int a,b,c,d;
while(cin>>a>>b>>c>>d)
{
getchar();
if(a==0) a=10;
if(b==0) b=10;
if(c==0) c=10;
if(d==0) d=10;
cout<<s1[a*3-2]<<s1[a*3-1]<<s1[a*3]<<s1[b*3-2]<<s1[b*3-1]<<s1[b*3]<<s1[c*3-2]<<s1[c*3-1]<<s1[c*3]<<s1[d*3-2]<<s1[d*3-1]<<s1[d*3]<<endl;
cout<<s2[a*3-2]<<s2[a*3-1]<<s2[a*3]<<s2[b*3-2]<<s2[b*3-1]<<s2[b*3]<<s2[c*3-2]<<s2[c*3-1]<<s2[c*3]<<s2[d*3-2]<<s2[d*3-1]<<s2[d*3]<<endl;
cout<<s3[a*3-2]<<s3[a*3-1]<<s3[a*3]<<s3[b*3-2]<<s3[b*3-1]<<s3[b*3]<<s3[c*3-2]<<s3[c*3-1]<<s3[c*3]<<s3[d*3-2]<<s3[d*3-1]<<s3[d*3]<<endl;
}
return 0;
}
方法二
#include<iostream>
#include<algorithm>
using namespace std;
char c[5][35]=
{
" _ _ _ _ _ _ _ _ ",
"| | | _| _||_||_ |_ ||_||_|",
"|_| ||_ _| | _||_| ||_| _|",
};
int main()
{
int a[5];
while(cin>>a[0]>>a[1]>>a[2]>>a[3])
for(int k=0; k<3; k++)
{
for(int i=0; i<4; i++)
for(int j=a[i]*3; j<a[i]*3+3; j++)
cout<<c[k][j];
cout<<endl;
}
return 0;
}