网站 单页,网站适配手机怎么做,专门做讲座的英语网站,分分彩做号网站1052. 卖个萌 (20) 时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见#xff0c;我们假设一个表情符号是按下列格式输出的#xff1a; [左手]([左眼][口][右眼])[右手]… 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: yuebowhu163.com Created Time: Sat 17 Jun 2017 11:12:01 PM CST************************************************************************/#include stdio.h
#include string.h
#include stdlib.h
#include memory.hint 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;
} /************************************************************************* File Name: 1052_1.c Author: YueBo Mail: yuebowhu163.com Created Time: Tue 20 Jun 2017 08:42:52 PM CST************************************************************************/#include stdio.h
#include stdlib.hvoid read_expression(char array[][16], int* count){ char ch; int i 0; int j 0; while((ch getchar()) ! \n){ if(ch [){ i;j 0; } else if( ch ]){ array[i-1][j] \0; j 0;} else{ array[i-1][j] ch; j;} } *count i;
} int GetExpression(char arr[][16])
{char ch 0;int cnt 0;int loopi 0;while ((ch getchar()) ! \n){if (ch [){cnt;loopi 0;continue;}else if (ch ]){arr[cnt-1][loopi] \0;loopi 0;}else{arr[cnt-1][loopi] ch;loopi;}}return cnt;
}int main()
{char hands[16][16];char eyes[16][16];char mouse[16][16];int cnt;int loopi;// cnt GetExpression(hands);read_expression(hands, cnt);for (loopi 0; loopi cnt; loopi){int i 0;while (hands[loopi][i] ! \0){printf(%c, hands[loopi][i]);i;}}printf(\n);return 0;
}