using System;
namespace HiddenMessageC
{
class Program
{
static void Main(string[] args)
{
string encodedPinNumber = Console.ReadLine();
string startPostionString = Console.ReadLine();
int step = Convert.ToInt32(Console.ReadLine());
string pin = "";
int startPostion = startPostionString[0] - 'a';
pin += encodedPinNumber[startPostion] + encodedPinNumber[startPostion + step];
pin += encodedPinNumber[startPostion + 2 * step] + encodedPinNumber[startPostion + 3 * step];
Console.WriteLine(pin);
Console.Read();
}
}
}
On the first line is a text which length is greater than 4, composed only of digits from 0 to 9.
The second line encodes the index where the hidden Pin code in the text begins. Possible values are the letters a, b or c, and a indicates that the start index is 0, b that the start index is 1, and c that the start index is 2.
On the third line is a number that indicates how many characters we need to skip in the text from the fisrt line (starting with the starting index specified above) to discover the 4 digits of the PIN code.
If I input 123456789, a , 2 => I should get the 1357 result...But my result is => 100108.
Could you give me some suggestions please? :)
As Turo said, when you use the index to access a string, it will return
char
. When the twochar
fields perform+
operation, they will be automatically converted toint
.So try to use String.Substring Method to get an individual character.
Or store all characters in a list, and then use the index to access them.