HDU5007Post Robot

题目:HDU5007Post Robot

题目大意:给你一段字符,如果你碰到“Apple”, “iPhone”, “iPod”, “iPad”就输出“MAI MAI MAI!”,如果碰到Sony,就输出“SONY
DAFA IS GOOD!” 。注意大小写敏感。

解题思路:字符串遍历。

代码:

#include <cstdio>
#include <cstring>

const int maxn = 1e4 + 5;
const char *s1 = "MAI MAI MAI!";
const char *s2 = "SONY DAFA IS GOOD!";

char str[maxn];
int len;
bool is_sony (int k) {

	if (k + 3 >= len)
		return false;
	if (str[k] == 'S' && str[k + 1] == 'o' && str[k + 2] == 'n' && str[k + 3] == 'y')
		return true;
	return false;
}

bool is_apple (int k) {

	if (k + 4 >= len)
		return false;
	if (str[k] == 'A' && str[k + 1] == 'p' && str[k + 2] == 'p' && str[k + 3] == 'l' && str[k + 4] == 'e')
		return true;
	return false;
}

bool is_iphone (int k) {

	if (k + 5 >= len)
		return false;
	if (str[k] == 'i' && str[k + 1] == 'P' && str[k + 2] == 'h' && str[k + 3] == 'o' && str[k + 4] == 'n' && str[k + 5] == 'e')
		return true;
	return false;
}

bool is_ipod (int k) {

	if (k + 3 >= len)
		return false;
	if (str[k] == 'i' && str[k + 1] == 'P' && str[k + 2] == 'o' && str[k + 3] == 'd')
		return true;
	return false;

}

bool is_ipad (int k) {

	if (str[k] == 'i' && str[k + 1] == 'P' && str[k + 2] == 'a' && str[k + 3] == 'd')
		return true;
	return false;
}

int main () {

	while (gets (str) != NULL) {

		len = strlen (str);
		for (int i = 0; i < len; i++) {

			if (str[i] == 'A' && is_apple(i)) {

				printf ("%s\n", s1);
				i += 4;
			} else if (str[i] == 'S' && is_sony(i)) {
				printf ("%s\n", s2);
				i += 3;
			} else if (str[i] == 'i') {

				if (is_iphone(i)) {
					printf ("%s\n", s1);
					i += 5;
				} else if (is_ipod(i)) {
					printf ("%s\n", s1);
					i += 3;
				} else if (is_ipad(i)) {
					printf ("%s\n", s1);
					i += 3;
				}
			}
		}
	}
	return 0;
}
时间: 2024-08-30 12:08:47

HDU5007Post Robot的相关文章

HDU5007-Post Robot

题目链接 题意:出现Apple.iPod.iPhone.iPad时输出MAI MAI MAI!,出现Sony,输出SONY DAFA IS GOOD! 思路:水题,直接暴力求解 代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> using namespace std; int main() { st

CodeForces 321 A - Ciel and Robot

[题目链接]:click here~~ [题目大意]:一个robot 机器人 ,可以根据给定的指令行动,给你四种指令,robot初始位置是(0,0),指令一出,robot会重复行动,判断能否在无限行动的情况下经过点(n,m). [解题思路]其实仔细模拟一下,可以发现是有周期的,判断即可,见代码吧~~ 代码: #include <iostream> #include <algorithm> #include <bits/stdc++.h> using namespace

Robot Framework自动化测试(五)--- 开发系统关键字

最近一直在用robot framework 做自动化测试项目,老实说对于习惯直接使用python的情况下,被框在这个工具里各种不爽,当然,使用工具的好处也很多,降低了使用成本与难度:当然,在享受工具带来便利的同时也会受制于工具.对于特定的需求,工具没提供相关的Library和关键字的时候,就只能放弃了. 还好robot framework提供了 Evaluate 关键字,对于Evaluate 关键字的使用等有时间再讲.当robot framework 不能解决需求,我是直接写个.py 程序,通过

Robot Framework + Selenium2环境安装

操作系统环境:Windows XP 安装包: 1. 安装Python Python是一切的基础 版本:python-2.7.6.msi 下载地址:https://www.python.org/downloads/ 2. 安装wxPython wxPython是Python语言的一套GUI图形库:ride需要wxPython的支持 版本:wxPython2.8-win32-unicode-2.8.12.1-py27.exe 下载地址:http://sourceforge.net/projects/

Robot Framework常用关键字介绍

下面关键字全部由 Builtin 库提供,Builtin 为 Robot Framework 标准类库.Builtin库提供常用的关键字 1.log log 关键字就是编程语言里的"print"一样,可以打印任何你想打印的内容. 2.定义变量 通过"Set variable"关键字来定义变量 3.连接对象 "Catenate"关键字可以连接多个信息 加上"SEPARATOR="可以对多个连接的信息进行分割. 4.定义列表 通过

在linux下搭建Robot Framework

在linux下搭建自动化测试框架Robot Framework,可以实现多用户同时登录并进行自动化脚本编写,相互之间没有影响. linux系统:fedora 21 步奏 描述 动作 note 1 Install Python yum install python yum list python  /* can view which python version will be installed */ 2 Install easy_install sudo yum install python-

hdu-5673 Robot(默次金数)

题目链接: Robot Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如果机器人的当前位置在原点右侧,它同样可以 向左移动单位距离.一系列的移动(左移,右移,原地不动)定义为一个路径.问有多少种不同的路径,使得nn秒后机器人仍然位于坐标原点? 答案可能很大,只需输出答案对1,000,00

HDU 5007 Post Robot

Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1306    Accepted Submission(s): 941 Problem Description DT is a big fan of digital products. He writes posts about technological produc

HDU 1036 Robot Motion 深搜

 Description A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N north (up the page) S south (down the page) E east (t