-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
31 lines (30 loc) · 883 Bytes
/
Program.cs
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
using System;
namespace NumberOfLinesToWriteString
{
class Program
{
static void Main(string[] args)
{
int[] widths = { 4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 };
string S = "bbbcccdddaaa";
Console.WriteLine(NumberOfLines(widths, S));
}
static int[] NumberOfLines(int[] widths, string S)
{
int length = 0;
int line = 1;
for (int i = 0; i < S.Length; i++)
{
int width = widths[S[i] - 'a'];
if (length + width <= 100)
length += width;
else
{
line++;
length = width;
}
}
return new int[] { line, length };
}
}
}