Codeforces 344A Magnets
Description
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Sample Input
6
10
10
10
01
10
10
3
4
01
01
10
10
2
Hint
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets.
题意:给你一个数n,表示接下来会有n行 01或者 10,0表示磁极的正级,1,表示磁极的负极,目的是让你把这n个01或者10连接成一个字符串,判断这个字符串有多少快组成,也就是说有多少各连续的1,1或者0,0把这个长串分成了几个部分。。。
分析: 简单模拟,瞎搞。
code:
/*************************************************************************
> File Name: cf.cpp
> Author: PrayG
> Mail:
> Created Time: 2016年07月10日 星期日 12时57分34秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn = ;
string arr;
int main()
{
string str;
int n,ans= ;
cin >> n;
for(int t = ; t <= n; t++)
{
str.clear();
cin >> str;
if(t == )
{
arr += str;
}
else
{
int len = arr.length();
// printf("len = %d\n",len);
// cout <<"str = " << str << endl;
if(arr[len-] == str[])
{
//cout << "arr = " << arr << endl;
ans++;
}
arr += str;
}
}
cout << ans << endl;
return ;
}
最新文章
- 拥抱.NET Core,跨平台的轻量级RPC:Rabbit.Rpc
- bootstrap弹框
- JSBinding / Memory Management (GC)
- Oracle 怎么让id自增加
- Codevs 1904 最小路径覆盖问题
- getchar()与EOF
- 实现简易版的moment.js
- Ubuntu彻底删除/卸载mysql,php,apache
- JavaScript模块化 --- Commonjs、AMD、CMD、es6 modules
- C++一个类对象的大小计算
- 怎么使用小程序的data-*属性?
- 十、uboot 代码流程分析---run_main_loop
- plsql developer日期类型数据格式不对如何设置?
- Forward+ Shading架构
- [No0000174]Spring常用注解(收藏大全)
- D Tree Requests dfs+二分 D Pig and Palindromes -dp
- thinkphp中的AJAX返回ajaxReturn()
- MathType调整矩阵分隔线粗细的方法
- python的输出问题
- JDK源码学习之 java.util.concurrent.automic包