P1538 迎春舞会之数字舞蹈
洛谷原题链接https://www.luogu.org/problem/P1538
题目背景
HNSDFZ的同学们为了庆祝春节,准备排练一场舞会。
题目描述
在越来越讲究合作的时代,人们注意的更多的不是个人物的舞姿,而是集体的排列。
为了配合每年的倒计时,同学们决定排出——“数字舞蹈”。顾名思义就是所有人一起排成若干个数字 -___-|||| 更为创新的是,每个人都是趴在地上,保证横竖。
现在给出数字及其要求摆出的大小,请你编程,模拟同学们的优美姿态。
输入格式
第一行为k。k表示要摆出数字的大小。
第二行为全部由数字组成的字符串,即要摆出的几个数字。
输出格式
按题目要求输出。
下面是题解代码:
#include<stdio.h>
#include<string.h>
void kongge(int cout){
for(int i=0;i<cout;i++){
printf(" ");
}
}
void shuxian(int cout){
printf("|");
}
void henxian(int cout){
for(int i=0;i<cout;i++){
printf("-");
}
}
void fa(char ch,int n,int cout){
if(n==0){
if(ch=='1'||ch=='4') kongge(cout+2);
else {kongge(1);henxian(cout);kongge(1);}
}
if(n==cout+1){
if(ch=='1'||ch=='7'||ch=='0') kongge(cout+2);
else{kongge(1);henxian(cout);kongge(1);}
}
if(n==3+2*cout-1){
if(ch=='1'||ch=='4'||ch=='7') kongge(cout+2);
else{kongge(1);henxian(cout);kongge(1);}
}
if(n<cout+1||n>cout+1){
if(n<cout+1&&n!=0){
if(ch=='1'||ch=='2'||ch=='3'||ch=='7'){kongge(cout+1);shuxian(cout); }
else{
if(ch=='5'||ch=='6'){ shuxian(cout);kongge(cout+1);}
else {shuxian(cout);kongge(cout);shuxian(cout);}
}
}
if(n>cout+1&&n!=3+2*cout-1){
if(ch=='1'||ch=='3'||ch=='4'||ch=='5'||ch=='7'||ch=='9'){
kongge(cout+1);shuxian(cout);
}else{
if(ch=='2'){ shuxian(cout);kongge(cout+1);}
else{shuxian(cout);kongge(cout);shuxian(cout);}
}
}
}
printf(" ");
}
char str[10000];
int main(){
//freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
scanf("%s",str);
for(int i=0;i<3+2*n;i++){
for(int t=0;t<strlen(str);t++){
fa(str[t],i,n);
}
printf("\n");
}
}
return 0;
}