import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ // solution1(in); // solution2(in); solution3(in); } } /** * 正则 * * 连续多个0 等价于 一个0 * 连续多个1 等价于 一个1 * * @param in */ private static void solution1(Scanner in){ int n = Integer.parseInt(in.nextLine()); // 去掉空格符 String serial = in.nextLine().replaceAll(" ", ""); // 多个0替换成一个0 多个1替换成一个1 String result = serial.replaceAll("0{2,}", "0").replaceAll("1{2,}", "1"); System.out.println(result.length()); } /** * 动态规划 * * dp[i]表示前i个字符能够得到的最长交错序列长度 * * { dp[i-1] , char[i]=char[i-1] * dp[i] = { * { dp[i-1]+1, char[i]!=char[i-1] * * @param in */ private static void solution2(Scanner in){ int n = Integer.parseInt(in.nextLine()); // 去掉空格符 String serial = in.nextLine().replaceAll(" ", ""); int[] dp = new int[n]; dp[0] = 1; for(int i=1; i<n; i++){ if(serial.charAt(i) != serial.charAt(i-1)){ dp[i] = dp[i-1]+1; }else{ dp[i] = dp[i-1]; } } System.out.println(dp[n-1]); } /** * 模拟法: 数组 * @param in */ private static void solution3(Scanner in){ int n = in.nextInt(); int[] nums = new int[n]; int result = 0; for(int i=0; i<n; i++){ nums[i] = in.nextInt(); if(i == 0){ result = 1; }else{ if(nums[i] != nums[i-1]){ result++; } } } System.out.println(result); } }