1052. 卖个萌 (20)
1052. 賣個萌 (20)
時間限制 400 ms內存限制 65536 kB
代碼長度限制 8000 B
判題程序 Standard 作者 CHEN, Yue
萌萌噠表情符號通常由“手”、“眼”、“口”三個主要部分組成。簡單起見,我們假設一個表情符號是按下列格式輸出的:
[左手]([左眼][口][右眼])[右手]現給出可選用的符號集合,請你按用戶的要求輸出表情。
輸入格式:
輸入首先在前三行順序對應給出手、眼、口的可選符號集。每個符號括在一對方括號[]內。題目保證每個集合都至少有一個符號,并不超過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? @\/@ 自己寫的下面這個代碼,感覺什么問題都沒有,但是只有一個測例可以通過,代碼如下: /*************************************************************************> File Name: 1052.c> Author: YueBo> Mail: yuebowhu@163.com> Created Time: Sat 17 Jun 2017 11:12:01 PM CST************************************************************************/#include <stdio.h> #include <string.h> #include <stdlib.h> #include <memory.h>int main() {char zifu[3][64] = {0};int index[3][64] = {0};int user[1024][5];int sz[3] = {0};int K;int i, j, k;int val;char buffer[128] = {0};int idx[5] = {0,1,2,1,0};int flag;for (i = 0; i < 3; i++){gets(zifu[i]);}for (i = 0; i < 3; i++){j = 0;k = 0;while (zifu[i][j] != '\0'){if (zifu[i][j] == '['){index[i][k] = j;k++;}if (zifu[i][j] == ']'){zifu[i][j] = 0;}j++; }sz[i] = k;}/*for (i = 0; i < 3; i++){for (j = 0; j < sz[i]; j++){printf("%s", &zifu[i][index[i][j]+1]);}printf("\n");} */scanf("%d", &K);for (i = 0; i < K; i++){for (j = 0; j < 5; j++){scanf("%d", &user[i][j]);}}for (i = 0; i < K; i++){flag = 0;memset(buffer, 0, 128);for (j = 0; j < 5; j++){val = user[i][j];if (val > sz[idx[j]]){flag = 1;printf("Are you kidding me? @\\/@");break;}strcat(buffer, &zifu[idx[j]][index[idx[j]][val-1]+1]);strcat(buffer, j == 0 ? "(" : "");strcat(buffer, j == 3 ? ")" : "");}printf("%s", flag == 0 ? buffer : "");printf("\n");}return 0; }下面這段代碼和自己的思想差不多,只不過博主把內容解析出來單獨存了起來,原文參見http://blog.csdn.net/chr1991/article/details/51014817
從下面這個代碼中得到的啟發是,一個任務要進行適當的分解,一步一步的解決,不要一下子把幾步的事情一下了了,這樣的代碼看起來很簡潔,但是自己寫的時候困難(調的時候困難),別人理解起來困難,分成一步一步的,不要耍快耍酷,怎么清楚明白怎么來.
具體到本題就是:
第1步:把眼,口,手,表情包分別解析出來,存到單獨的內存中;
第2步:根據用戶請求直接把表情調出來;
#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]); } 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; } #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]); } 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; }
總結
以上是生活随笔為你收集整理的1052. 卖个萌 (20)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (JAVA)Object类之String
- 下一篇: python excel图表 导出wor