Thursday 11 May 2017

String Searching : what is your mobile number?

These days Bechan Chacha is depressed because his crush gave him list of mobile number some of them are valid and some of them are invalid. Bechan Chacha has special power that he can pick his crush number only if he has valid set of mobile numbers. Help him to determine the valid numbers.
You are given a string "S" and you have to determine whether it is Valid mobile number or not. Mobile number is valid only if it is of length 10 , consists of numeric values and it shouldn't have prefix zeroes.

Input:
First line of input is T representing total number of test cases.
Next T line each representing "S" as described in in problem statement.

Output:
Print "YES" if it is valid mobile number else print "NO".
Note: Quotes are for clarity.
Constraints:
1<= T <= 103
sum of string length <= 105



SAMPLE INPUT
3
1234567890
0123456789
0123456.87
SAMPLE OUTPUT
YES
NO
NO


















Solution to the Problem
using System; 
using System.Numerics;
class MyClass {
    static void Main(string[] args) {
        
string line1 = System.Console.ReadLine().Trim();
var N = Int32.Parse(line1);
string[] arr = new string[N];
 for (var i = 0; i < N; i++)
   {
   arr[i] = Console.ReadLine();
   }
for (var i = 0; i < N; i++)
{
 try
{
var str = (Convert.ToInt64(arr[i]).ToString().Length == 10) ? "YES" :  "NO";
 Console.WriteLine(str); 
 }
 catch
 {
  Console.WriteLine("NO");
 }
 }
 }
}










No comments:

Post a Comment

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...