Code Forces Problem Way Too Long Words

So I am trying to solve problem way too long words from codeforces here 's the link to check it https://codeforces.com/problemset/problem/71/A now in my code i have created logic for word which have more than 10 characters would become in a special abbrevations and words which are less than 10 characters would be print as it is but i am not able to filter and remove int if user inputs integer with string here is my code
C#

internal class Program
{
private static void Main(string[] args)
{
string name = Console.ReadLine();
var convert = Convert.ToInt32(name);
int strlength = name.Length;
if(strlength > 10)
{
char[] split = name.ToCharArray();
int charCount = strlength - 2;
int lastChar = split.Length - 1;
Console.WriteLine("{0}{1}{2}", split[0], charCount, name[lastChar]);
}

else
{
Console.WriteLine(name);
}
}
}
C#

internal class Program
{
private static void Main(string[] args)
{
string name = Console.ReadLine();
var convert = Convert.ToInt32(name);
int strlength = name.Length;
if(strlength > 10)
{
char[] split = name.ToCharArray();
int charCount = strlength - 2;
int lastChar = split.Length - 1;
Console.WriteLine("{0}{1}{2}", split[0], charCount, name[lastChar]);
}

else
{
Console.WriteLine(name);
}
}
}
3 Replies
Sehra
Sehra5d ago
you need to read the first line, parse that as int n, then loop n times, reading a line each time, do the thing and write the result
Technical Developer
ok let me try
yourFriend
yourFriend4d ago
Also break the problem into separate methods like for 1. Parsing int where (1 <= int <= 100) 2. Parsing string validating they are not null or empty or whitespace and length <= 100. 3. Solving problem (here abbreviating words whose length >10)

Did you find this page helpful?