using System;
public class GFG{
static public void Main (){
string s=Console.ReadLine();
//1) Print the input string
Console.WriteLine(s);
//2) Length of the string without using library function
int count=0;
foreach(var literal in s)
{
count++;
}
Console.WriteLine(count);
foreach(var literal in s)
{
Console.Write("{0} ",literal);
}
Console.WriteLine();
//3) string in reverse order without inbuilt method
char[] arr=s.ToCharArray();
int i=0,j=s.Length-1;
while(i<j)
{
char temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j--;
}
//4) count total number of the string
string s1="Welcome to India";
string[] res1=s1.Split(" ");
int count1=0;
foreach(var item in res1)
{
count1++;
}
Console.WriteLine(count1);
//5) compare 2 string without using library function
string s11="Hai";
string s21="hai";
int ii=0,jj=s21.Length-1;
int count2=1;
while(ii<jj)
{
if(s11[ii]!=s21[ii] || s11[jj]!=s21[jj])
{
count2=0;
break;
}
ii++;
jj--;
}
if(count2==1)
Console.WriteLine("Equal");
else
Console.WriteLine("Not Equal");
}
}
//6) Reverse each string without using split(" ")
i/p: Hai welcome to digital
o/p: iaH emoclew ot latigid
using System;
using System.Text;
public class GFG{
static public void Main (){
StringBuilder str=new StringBuilder("Hai welcome to digital");
int i=0,l=str.Length-1;
int start=0;
while(i<=l)
{
if(str[i]==' ')
{
swap(str,start,i-1);
start=i+1;
}
if(i==l)
{
swap(str,start,i);
}
i++;
}
Console.WriteLine(str);
}
public static void swap(StringBuilder str,int i,int l)
{
while(i<=l)
{
char t=str[i];
str[i]=str[l];
str[l]=t;
i++;
l--;
}
}
}
