浙大 PAT b1052
#include <stdio.h>
#include <string.h>char *pump(char a[]) { // 表情提取函数,识别开始的'[' ,记录表情,到']'结束,遇到换行符表示录入结束,返回NULLchar c = 0;memset(a, 0, 5);while ((c = getchar()) != '[')if (c == '\n') return NULL;for (int i = 0; (c = getchar()) != ']'; i++)a[i] = c;return a;
}int store(char db[][5], char a[]) { // 存储读取到的表情,并返回读到的表情个数因为个数从0开始记,返回i-1int i = 0;for (; pump(a) != NULL; i++)strcpy(db[i], a);return i - 1;
}void print(char db[][11][5], int size[]) { // 读取请求并输出表情int a[5], tag = 1;for (int i = 0; i < 5; i++) { // 读取一组表情请求的序号scanf("%d", a+i);a[i] -= 1; // 同样的,转换为0开始的序号if (a[i] > size[i] || a[i] < 0) tag = 0; // 遇到不存在的序号,标记tag为0}if (tag) // 根据请求的序号是否全存在,选择输出模式printf("%s(%s%s%s)%s\n", db[0][a[0]], db[1][a[1]], db[2][a[2]], db[1][a[3]], db[0][a[4]]);// db为表情存储数组,根据序号选择对应表情elseprintf("Are you kidding me? @\\/@\n");
}int main() {char a[5], db[3][11][5] = {0};int n, size[5] = {0};for (int i = 0; i < 3; i++)size[i] = store(db[i], a); // 根据store函数返回的值,记录改组表情的个数,从而判断请求是否合理size[4] = size[0], size[3] = size[1]; // 因为两只眼睛,两只手,所以3和4的可选范围与左边对称scanf("%d", &n);for (int i = 0; i < n; i++) // 输出n次请求的表情print(db, size);return 0;
}
浙大 PAT b1052相关推荐
- 浙大pat | 浙大pat 牛客网PAT顶级(Top Level)练习题 1001
1001 LUCKY STRING 1872 8254 22% 题目描述 A string s is LUCKY if and only if the number of differentchara ...
- 浙大PAT甲级1040
浙大PAT甲级1040 原题 问题分析 原题 1040 Longest Symmetric String (25 分) Given a string, you are supposed to outp ...
- 浙大PAT甲级1019. General Palindromic Number (20)
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- 浙大 PAT b1040
#include <stdio.h> #include <string.h> int main() {char str[100001];gets(str);int numT = ...
- 浙大PAT 1003题 1003. Emergency
本题用Dfs搜索或者Dijkstra算法都可以,当然也有其它的方法.这题感觉是pat中常见的类型,非常重要. Dfs搜索代码: #include<stdio.h> int road[510 ...
- 浙大PAT甲级1027. Colors in Mars (20)
1027. Colors in Mars (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People ...
- 浙大PAT甲级1006
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 浙大PAT乙级1004. 成绩排名 (20)
1004. 成绩排名 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入n名学生的姓名.学号.成绩,分 ...
- 浙大 PAT 甲级1009
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
最新文章
- 无重复字符的最长子串_滑动窗口
- mysql主从同步错误记录。
- 爆炸了!刚刚!小姐姐说她找了个程序员男友
- composer 下载包慢的解决方法
- springfox源码_springfox 源码分析(七) 文档初始化
- 神奇的反爬措施--大众点评
- 改变输出格式,提高手机照片质量
- mysql 获得年月函数_mysql之日期函数
- 【AT91SAM9261EK】u-boot 2022 tftpboot 烧写根文件系统
- amazon s3cmd 安装、批量下载
- Pytorch 深度学习入门与实践 第二章 pytorch快速入门 (1)
- Halcon 3D点云和深度图的相互转化
- 主机名以及内外部命令
- 2022年最新NFT 开发平台解决方案
- 余额宝 算法 php,把10000元放进余额宝,一年后支付宝会给多少利息?你计算过吗?...
- 字符串strip()介绍
- java lam表达式_详细分析Java Lambda表达式
- configobj安装_linux (centos)安装Anaconda
- 探访世优科技数字人虚拟直播产品体系 | 世优开放日再次成功举行
- 反脆弱性的软件架构 - 微服务