You have to be at your work as soon as possible. The road on your route to work may consist of two types of surface: asphalt or sand. To simplify the description, it will be denoted by a string R consisting only of the letters: "A" for an asphalt segment and "S" for a sand segment. All segments represent the same distance. For example, R = "SAAS" describes a road comprising of sand, asphalt, asphalt and sand segments.
When you go on foot, you need 20 minutes to pass through an asphalt segment and 30 minutes through a sand segment. You also have an electric scooter, which needs 5 minutes to pass through an asphalt segment and 40 minutes through a sand segment.
You start your journey on the scooter, but at any point you can get off the scooter and go on foot for the rest of the journey. What is the shortest time in which you can get to work?
Write a function:
class Solution { public int solution(string R); }
that, given a string R of length N, representing the road to work, returns the minimum time that you need to get to work.
Examples:
1. Given R = "ASAASS", your function should return 115. You ride on the scooter over the first four segments ("ASAA") in 5 + 40 + 5 + 5 = 55 and then you go on foot through "SS" in 30 + 30 = 60. Altogether, your journey will take 55 + 60 = 115.
2. Given R = "SSA", the function should return 80. You do not ride on the scooter at all, and you go on foot in 30 + 30 + 20 = 80.
3. Given R = "SSSSAAA", the function should return 175. You ride on the scooter all the time in 40 + 40 + 40 + 40 + 5 + 5 + 5 = 175.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string R is made only of the characters 'S' and/or 'A'.
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return 0;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if()
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' &&){
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && ){
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index){
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
Compilation failed: 1 error(s), 0 warnings Solution.cs(9,16): error CS0161: `Solution.solution(string)': not all code paths return a value
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
Route(R)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
Compilation failed: 1 error(s), 0 warnings Solution.cs(12,5): error CS1002: ; expected
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write your code in C# 6.0 with .NET 4.5 (Mono)
return Route(R)
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
index++
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A' && index==0){
sum = sum + 5;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
sum = sum + 5;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
sum = sum + 5;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
sum = sum + 5;
continue;
}
if (i <= index )
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
sum = sum + 5;
continue;
}
if (i <= index && index!=0;)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
Compilation failed: 3 error(s), 0 warnings Solution.cs(42,46): error CS1026: Unexpected symbol `;', expecting `)' Solution.cs(42,47): error CS1026: Unexpected symbol `)', expecting `)' Solution.cs(53,20): error CS1525: Unexpected symbol `else'
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if(text[0]=='A'){
sum = sum + 5;
continue;
}
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route();
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route("ASAASS");
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route("ASAASS");
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for(int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (i <= index && index!=0)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] == 'A')
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] == 'A')
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] == 'A' )
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] == 'A' &&index==0)
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] == 'A' && index==0)
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] = 'A' && index==0)
{
index++;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] != 'A' && index==0)
{
index--;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] != 'A' && index==0)
{
index--;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string R) {
// write you;r code in C# 6.0 with .NET 4.5 (Mono)
return Route(R);
}
public static int Route(string text)
{
int Acount = 0;
int count = 0;
int index = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == 'A')
{
count = count + 15;
}
else
{
count = count - 10;
}
if (count > Acount)
{
Acount = count;
index = i;
}
}
int sum = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[0] != 'A' && index==0)
{
index--;
}
if (i <= index)
{
if (text[i] == 'A')
{
sum = sum + 5;
}
else
{
sum = sum + 40;
}
}
else
{
if (text[i] == 'A')
{
sum = sum + 20;
}
else
{
sum = sum + 30;
}
}
}
return sum;
}
}
The solution obtained perfect score.
Medium tests, getting off the scooter at a random position. N <= 10,000.