UVa 1585 Score
2016-05-21 09:18
239 查看
本题是较为简单的字符串匹配问题,在匹配过程中遇到’O’则累加,遇到’X’则重置0,以下是代码部分
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; char str[81]; //输入的目标匹配串 int score[81]; //累加计数变量 int main() { int n; scanf("%d",&n); while (n --) { scanf("%s",str); score[0] = (str[0] == 'O'); for (int i = 1 ; str[i] ; ++ i) { //str[i]=='\0'时退出循环 score[i] = score[i-1]+1; //变量累加 if (str[i] == 'X') score[i] = 0; } int sum = 0; for (int i = 0 ; str[i] ; ++ i) sum += score[i]; printf("%d\n",sum); } return 0; }
相关文章推荐
- const引用与非const引用
- 使用 HTML5 WebSocket 构建实时 Web 应用
- Windows快捷键
- convert View to Bitmap将View保存为图片
- Java xml解析器SAX解析与StAX解析比较
- Java修饰符
- 【bzoj 1010】[HNOI2008] 玩具装箱toy(斜率优化dp)
- (Jmeter 三)JMETER+WEBSERVICE性能测试
- 三个时间属性 atime ctime mtime
- gcc arm-linux-gcc编译优化
- 大数据,环境搭建,基础;
- C++实现K-means,聚类原理解析(并用在图片像素点聚类)
- 请问人工神经网络中的activation function的作用具体是什么?为什么ReLu要好过于tanh和sigmoid function?
- Swift 可选值
- 使用iCamera 测试AR0331 300w高分辨率摄像头小结
- 图解win7下ping命令使用
- find 搜索命令
- LeetCode 61. Rotate List(旋转链表)
- 命令行参数解析函数getopt_long() 使用详解
- iPhone私有API