-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConsecutive_1's.cs
More file actions
43 lines (39 loc) · 1.15 KB
/
Consecutive_1's.cs
File metadata and controls
43 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string result = "";
while(n > 1){
int r = n % 2;
result = Convert.ToString(r) + result;
n /= 2;
}
result = Convert.ToString(n) + result;
int cons_pairs = 0, max = 0, j;
for(int i = 0; i < result.Count() - 1; i++){
j = i+1;
if(result[i] == '1' & result[j] == '1'){
cons_pairs += 1;
}
if(result[i] == '1' & result[j] == '0'){
if(cons_pairs >= max){
max = cons_pairs;
}
cons_pairs = 0;
}
}
Console.WriteLine(max + 1);
}
}