Time Lapse :NONE 1289.cpp123456789101112131415161718#include <iostream>using namespace std;int main() { int tc = 1, T; char c, prev; scanf("%d",&T); getchar_unlocked(); while(T--) { prev = c = getchar_unlocked(); int ans = 1; bool flag = c == '0' ? false : true; for(c = getchar_unlocked(); c == '1' || c == '0' ; prev = c, c = getchar_unlocked()) { if(flag && prev != c) ++ans; if(c == '1') flag = true; } printf("#%d %d\n",tc++, ans); }} 1289.java12345678910111213141516171819202122232425import java.util.Scanner;public class Solution { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int tc = 1; int T; String input; T = sc.nextInt(); while(T-- != 0) { input = sc.next(); int ans = 1; boolean flag = false; for(int i = 0; i < input.length() - 1; ++i) { if(input.charAt(i) == '1') flag = true; if (flag) { if(input.charAt(i) != input.charAt(i + 1)) ++ans; } } System.out.println("#" + tc++ + " " + ans); } }}