博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电 Problem 3788 ZOJ问题
阅读量:7091 次
发布时间:2019-06-28

本文共 1383 字,大约阅读时间需要 4 分钟。

ZOJ问题

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3624    Accepted Submission(s): 1086
Problem Description
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
是否AC的规则如下:
1. zoj能AC;
2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;
3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
 
Input
输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000;
 
Output
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
 
Sample Input
 
zoj ozojo ozoojoo oozoojoooo zooj ozojo oooozojo zojoooo
 
Sample Output
 
Accepted Accepted Accepted Accepted Accepted Accepted Wrong Answer Wrong Answer

 这道题不是太难,主要讨论a、b、c之间的关系,但是注意a、b、c数值的讨论。

#include 
#include
#define MAX_N 10005using namespace std;int main(){ char str[MAX_N]; while (scanf("%s", &str) != EOF) { int a, b, c; int z = 0, j = 0; bool flag = false; int len = strlen(str); for (int i = 0; i < len; i++) { if (str[i] == 'z') z++; if (str[i] == 'j') j++; } if(z != 1 || j != 1) flag = true; if (flag) { printf("Wrong Answer\n"); continue; } for (int i = 0; i < len; i++) { if (str[i] == 'z') { a = i; } if (str[i] == 'j') { b = i - a - 1; c = len - i - 1; break; } } if (a == 0 && c == 0 && b != 0) printf("Accepted\n"); else if (a * b == c && c) printf("Accepted\n"); else printf("Wrong Answer\n"); } return 0;}

转载于:https://www.cnblogs.com/cniwoq/p/6770969.html

你可能感兴趣的文章
linux
查看>>
CentOS6.5+Puppet3.7.3 安装、配置及测试
查看>>
grep、egrep及相应的正则表达式和用法
查看>>
GATHER_STATS_JOB: Stopped by Scheduler. Consider increasing the maintenance window duration if this
查看>>
linux和windows下的clock函数
查看>>
seq命令
查看>>
JsonUtils 工具类
查看>>
shell 编写脚本批量ping ip
查看>>
MySQL5.6在线表结构变更(online ddl)总结
查看>>
人人都能学编程
查看>>
使用loadrunner进行报表导出下载的性能测试
查看>>
局域网共享
查看>>
sudo、磁盘配额、数组、信号捕捉
查看>>
niceTitle插件
查看>>
查看mysql数据库表大小
查看>>
Azure负载均衡机制与会话粘滞需求
查看>>
leetCode 121. Best Time to Buy and Sell Stock 数组
查看>>
查看硬件信息几种方法
查看>>
MikroTik RouterOS-常用配置命令
查看>>
LVS DR + Keepalived 负载均衡配置详解(测试篇)
查看>>