1052 卖个萌 (20分)
思路:定义三个二维数组,分别表示手,眼睛和嘴巴,然后再分别为其定义计数变量,在通过getchar()依次输入,其中值得注意的是,通过
scanf("%[^]])"来读到 ]的位置结束(
格式化字符串
“%[^…]”
,这种字符串的作用类似于"%s",但是后者会读取字符串到空白字符(空格、换行、制表符等等),前者使scanf读到^后面的字符,相当于用户可以自定义scanf的行为
通过这个读取之后,在根据输入输出,如果输入的编号超过计数或者小于1,就打印are you kidding me,最后还需要注意的就是转义字符,要打出\需要\来转义
#include<stdio.h>
#include<string.h>
int main(void)
{
char hand[10][5];
char eye[10][5];
char mouth[10][5]; //用于存放原始的三组字符,因为为了便于区分是第几个[]里的字符,所以采用了数组的方法存储;
int i=0,j=0;
int num_hand=0;
int num_eye=0;
int num_mouth=0; //用于记录存放的字符的个数;
char c;
for(i=0;(c=getchar())!='\n';) //要实现数据的输入,而不把[]输进去,用了 scanf("%[^]]")这个输入用法用于输入 ]之前的字符串;
{
if(c=='[')
{
scanf("%[^]]",hand[++num_hand]); //采用++num_hand 从1开始,而不是从零才是;
}
}
for(i=0;(c=getchar())!='\n';)
{
if(c=='[')
{
scanf("%[^]]",eye[++num_eye]);
}
}
for(i=0;(c=getchar())!='\n';)
{
if(c=='[')
{
scanf("%[^]]",mouth[++num_mouth]);
}
}
int n;
scanf("%d",&n);
int num[6];
i=0;
for(i=0;i<n;i++)
{
scanf("%d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4]);
if(num[0]>=1&&num[1]>=1&&num[2]>=1&&num[3]>=1&&num[4]>=1&&num[0]<=num_hand&&num[1]<=num_eye&&num[2]<=num_mouth&&num[3]<=num_eye&&num[4]<=num_hand)
//只有当num数组中全部的数小于等于相应表情的个数,并且num的数要大于0时才可以输出;
{
printf("%s(%s%s%s)%s\n",hand[num[0]],eye[num[1]],mouth[num[2]],eye[num[3]],hand[num[4]]);
}
else
{
printf("Are you kidding me? @\\/@\n"); //要注意如何输出/
}
}
return 0;
}