PAT (Basic Level) Practise (中文)1039. 到底买不买(20) C语言
来源:互联网 发布:windows活动目录 编辑:程序博客网 时间:2024/05/26 20:25
1039. 到底买不买(20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。
为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。
图 1
输入格式:
每个输入包含1个测试用例。每个测试用例分别在2行中先后给出摊主的珠串和小红想做的珠串,两串都不超过1000个珠子。
输出格式:
如果可以买,则在一行中输出“Yes”以及有多少多余的珠子;如果不可以买,则在一行中输出“No”以及缺了多少珠子。其间以1个空格分隔。
输入样例1:ppRYYGrrYBR2258YrR8RrY输出样例1:
Yes 8输入样例2:
ppRYYGrrYB225YrR8RrY输出样例2:
No 2
提交代码
水题,哈哈。
AC代码如下:
#include<stdio.h>#include<string.h>int main(){char sell[10010]={0};char want[10010]={0};int count=0,i,j;gets(sell);gets(want);for(i=0;i<strlen(want);i++){if(strchr(sell,want[i])){sell[strchr(sell,want[i])-sell]=' ';}else{count++;}}if(count){printf("No %d",count);}else{printf("Yes %d",strlen(sell)-strlen(want));}return 0;}
0 0
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20) C语言
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
- PAT (Basic Level) Practise (中文)1044. 火星数字(20) C语言
- PAT (Basic Level) Practise (中文)1022. D进制的A+B (20) C语言
- PAT (Basic Level) Practise (中文)1002. 写出这个数 (20) C语言
- PAT (Basic Level) Practise (中文)1003. 我要通过!(20) C语言
- PAT (Basic Level) Practise (中文)1024. 科学计数法 (20) C语言
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20) C语言
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20) C语言
- PAT (Basic Level) Practise (中文)1008. 数组元素循环右移问题 (20) C语言
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20) C语言
- PAT (Basic Level) Practise (中文)1013. 数素数 (20) C语言
- PAT (Basic Level) Practise (中文)1017. A除以B (20) C语言
- PAT (Basic Level) Practise (中文)1023. 组个最小数 (20)C语言
- PAT (Basic Level) Practise (中文)1027. 打印沙漏(20) C语言
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)C语言
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20) C语言
- 查看策略应用结果
- 暑期集训搜索专题(一)
- HDU 1869--六度分离 【任意点最短路】
- webkit 与 webcore
- zoj2104
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20) C语言
- PCB参数计算神器-Saturn PCB Design Toolkit下载及安装指南
- Leetcode 14 Longest Common Prefix
- leetcode[137]:Single Number II
- 合并多个文本文件方法
- [cogs 886]完美的牛栏
- linux下安装mysql(server和client)
- PHP防注入攻击
- UVA1225 Digit Counting