P1538 迎春舞会之数字舞蹈
依旧是~骚粉色。
值得注意的是:这道题里面说的并不是数字前要输出空格,而是数字后。
被坑在这里。
题意:给出一系列数字,和一个k值,用k大的横线或者竖线表示数字。
题解:预处理一下每个数字什么时候要输出,什么时候不要。最多只需要7条线来表示。
两种解法:第一种我的,第二种大佬的。
但是总体思想一致,只是他的比较简洁。
引用:https://www.luogu.org/problemnew/solution/P1538
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k;
string s,m[10]={"-|| ||-"," | | ","- |-| -",
"- |- |-"," ||- | ", "-| - |-","-| -||-",
"- | | ","-||-||-","-||- |-"};
cin>>k>>s;
for (int p=0;p<7;p++){
if (p==2 || p==5) continue;
if (p%3==0){
for (int i=0;i<s.size();i++){
cout<<' ';
for (int j=0;j<k;j++){
cout<<m[s[i]-48][p];
}
cout<<" ";
}
cout<<endl;
}else{
for(int q=0;q<k;q++){
for (int i=0;i<s.size();i++){
cout<<m[s[i]-48][p];
for (int j=0;j<k;j++){
cout<<' ';
}
cout<<m[s[i]-48][p+1]<<' ';
}
cout<<endl;
}
}
}
return 0;
}
剩下是我的:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char str[10][7]={
{1,1,1,0,1,1,1},{0,0,1,0,0,1,0},{1,0,1,1,1,0,1},{1,0,1,1,0,1,1},
{0,1,1,1,0,1,0},{1,1,0,1,0,1,1},{1,1,0,1,1,1,1},{1,0,1,0,0,1,0},
{1,1,1,1,1,1,1},{1,1,1,1,0,1,1},
};
int main()
{
string a;
int k;
cin>>k>>a;
int flag;
for(int i=0;i<2*k+3;i++)
{
if(i==0||i==k+1||i==2*k+2)
{
if(i==0)flag=0;
if(i==k+1)flag=3;
if(i==2*k+2)flag=6;
for(int j=0;j<a.size();j++)
{
cout<<" ";
if(str[a[j]-'0'][flag])
{
for(int x=1;x<=k;x++)
{
cout<<"-";
}
}
else
{
for(int x=1;x<=k;x++)
{
cout<<" ";
}
}
cout<<" ";
}
}
else if(i<k+1)
{
for(int j=0;j<a.size();j++)
{
flag=1;
if(str[a[j]-'0'][flag])
{
cout<<"|";
}
else cout<<" ";
flag=2;
for(int x=1;x<=k;x++)
{
cout<<" ";
}
if(str[a[j]-'0'][flag])
{
cout<<"|";
}
else cout<<" ";
cout<<" ";
}
}
else
{
for(int j=0;j<a.size();j++)
{
flag=4;
if(str[a[j]-'0'][flag])
{
cout<<"|";
}
else cout<<" ";
flag=5;
for(int x=1;x<=k;x++)
{
cout<<" ";
}
if(str[a[j]-'0'][flag])
{
cout<<"|";
}
else cout<<" ";
cout<<" ";
}
}
cout<<endl;
}
}