PAT乙級1052(C語言)-賣個萌 (20)

萌萌噠表情符號通常由“手”、“眼”、“口”三個主要部分組成。簡單起見,我們假設一個表情符號是按下列格式輸出的:

[左手]([左眼][口][右眼])[右手]

現給出可選用的符號集合,請你按用戶的要求輸出表情。

輸入格式:

輸入首先在前三行順序對應給出手、眼、口的可選符號集。每個符號括在一對方括號[]內。題目保證每個集合都至少有一個符號,並不超過10個符號;每個符號包含1到4個非空字符。

之後一行給出一個正整數K,爲用戶請求的個數。隨後K行,每行給出一個用戶的符號選擇,順序爲左手、左眼、口、右眼、右手——這裏只給出符號在相應集合中的序號(從1開始),數字間以空格分隔。

輸出格式:

對每個用戶請求,在一行中輸出生成的表情。若用戶選擇的序號不存在,則輸出“Are you kidding me? @\/@”。

輸入樣例:
[╮][╭][o][~\][/~]  [<][>]
 [╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^]  ...
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3
輸出樣例:
╮(╯▽╰)╭
<(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@

#include <stdio.h>  
#define MAX 5  
#define MAX_CH 10  
void read_expression(char array[][MAX], int* count);
int main(int argc, const char * argv[]) {
  char hand[MAX_CH][MAX], eye[MAX_CH][MAX], month[MAX_CH][MAX];
  int k, hand1, eye1, month1, eye2, hand2;
  int i, hand_count = 0, eye_count = 0, month_count = 0;
  read_expression(hand, &hand_count);
  read_expression(eye, &eye_count);
  read_expression(month, &month_count);
  scanf("%d", &k);
  for (i = 0; i < k; i++) {
    scanf("%d %d %d %d %d", &hand1, &eye1, &month1, &eye2, &hand2);
    if (hand1 <1 || hand1 > hand_count || hand2 < 1 || hand2 > hand_count) {
      printf("Are you kidding me? @\\/@\n");
      continue;
    }
    if (eye1 <1 || eye1 > eye_count || eye2 < 1 || eye2 > eye_count) {
      printf("Are you kidding me? @\\/@\n");
      continue;
    }
    if (month1 < 1 || month1 > month_count) {
      printf("Are you kidding me? @\\/@\n");
      continue;
    }
    printf("%s(%s%s%s)%s\n", hand[hand1 - 1], eye[eye1 - 1], month[month1 - 1], eye[eye2 - 1], hand[hand2 - 1]);
  }
  system("pause");
  return 0;
}
void read_expression(char array[][MAX], int* count) {
  int i, j, flag;
  char temp;
  i = 0;
  j = 0;
  flag = 0;
  while ((temp = getchar()) != '\n') {
    if (temp == '[' && !flag) {
      j = 0;
      flag = 1;
    }
    else if (temp == ']' && flag) {
      array[i][j] = '\0';
      i++;
      flag = 0;
    }
    else if (flag) {
      array[i][j++] = temp;
    }
  }
  *count = i;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章