using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace finalxmlfemale
{
class Program
{
public static void xmlfemale(string input1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(input1);
XmlNode node = xmldoc.DocumentElement;
StringBuilder sb = new StringBuilder();
foreach (XmlNode b in node.ChildNodes)
{
sb.Append(b.InnerText);
sb.Append(' ');
}
sb.Append("\n");
XmlNodeList list = xmldoc.SelectNodes("/Names/Name[@type='F']");
foreach(XmlNode n in list)
{
sb.Append(n.InnerText);
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
string n = "<Names><Name type='F'>shweta</Name><Name type='M'>sumit</Name><Name type='F'>pooja</Name></Names>";
Program.xmlfemale(n);
}
}
}
27.xml name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace finalxmlname
{
class Program
{
public static void xmlname(string input1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(input1);
XmlNode node=xmldoc.DocumentElement;
StringBuilder sb=new StringBuilder();
XmlNodeList list = xmldoc.SelectNodes("/Names/Name");
foreach (XmlNode n in list)
{
sb.Append(n["FirstName"].InnerText);
sb.Append(' ');
sb.Append(n["LastName"].InnerText);
sb.Append(' ');
}
string output1 = sb.ToString();
Console.WriteLine(output1);
}
static void Main(string[] args)
{
string n = "<Names><Name><FirstName>John</FirstName><LastName>Smith</LastName></Name><Name><FirstName>James</FirstName><LastName>White</LastName></Name></Names>";
Program.xmlname(n);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace april24
{
class xml_Solution2
{
public static void FindAge(string x)
{
XmlDocument obj = new XmlDocument();
obj.LoadXml(x);
XmlNodeList xn = obj.SelectNodes("/students/student");
foreach (XmlNode item in xn)
{
DateTime dt = Convert.ToDateTime(item["dob"].InnerText);
int age = Convert.ToInt32((DateTime.Now - dt).TotalDays / 365.25);
if (age < 30)
{
Console.WriteLine(item["name"].InnerText);
Console.WriteLine(item["due"].Attributes["unit"].Value + item["due"].InnerText);
}
}
Console.ReadKey();
}
static void Main(string[] args)
{
FindAge(@"<?xml version='1.0' encoding='utf-8' ?>
<students>
<student id='S001'>
<name> Raj </name>
<dob>12-12-1980</dob>
<due unit='Rs.'>1000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S002'>
<name> Kaushik </name>
<dob>1-1-1945</dob>
<due unit='Rs.'>2000</due>
<address>
<city> Hyderabad </city>
<state>Andhra Pradesh</state>
</address>
</student>
<student id='S003'>
<name> Jasmine </name>
<dob>2-11-1975</dob>
<due unit='Rs.'>4000</due>
<address>
<city> Bangalore </city>
<state>Karnataka </state>
</address>
</student>
<student id='S004'>
<name>Ashok </name>
<dob>7-7-1987</dob>
<due unit='Rs.'>5000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S005'>
<name> Hillol </name>
<dob>12-1-1969</dob>
<due unit='Rs.'>2000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S006'>
<name> Pratim</name>
<dob>1-1-1945</dob>
<due unit='Rs.'>1000</due>
<address>
<city> Hyderabad </city>
<state>Andhra Pradesh</state>
</address>
</student>
</students>"
);
Console.ReadKey();
}
}
}
Find Name of student staying at kolkata
public static void FindAge(string x)
{
XmlDocument obj = new XmlDocument();
obj.LoadXml(x);
XmlNodeList xn = obj.SelectNodes("/students/student");
foreach (XmlNode item in xn)
{
XmlNodeList xn2 = item.SelectNodes("address");
foreach (XmlNode item2 in xn2)
{
string str = item2["city"].InnerText.Trim().ToLower();
if (str.Equals("kolkata"))
Console.WriteLine(item["name"].InnerText.Trim());
}
}
Console.ReadKey();
}
static void Main(string[] args)
{
FindAge(@"<?xml version='1.0' encoding='utf-8' ?>
<students>
<student id='S001'>
<name> Raj </name>
<dob>12-12-1980</dob>
<due unit='Rs.'>1000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S002'>
<name> Kaushik </name>
<dob>1-1-1945</dob>
<due unit='Rs.'>2000</due>
<address>
<city> Hyderabad </city>
<state>Andhra Pradesh</state>
</address>
</student>
<student id='S003'>
<name> Jasmine </name>
<dob>2-11-1975</dob>
<due unit='Rs.'>4000</due>
<address>
<city> Bangalore </city>
<state>Karnataka </state>
</address>
</student>
<student id='S004'>
<name>Ashok </name>
<dob>7-7-1987</dob>
<due unit='Rs.'>5000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S005'>
<name> Hillol </name>
<dob>12-1-1969</dob>
<due unit='Rs.'>2000</due>
<address>
<city> Kolkata </city>
<state>West Bengal </state>
</address>
</student>
<student id='S006'>
<name> Pratim</name>
<dob>1-1-1945</dob>
<due unit='Rs.'>1000</due>
<address>
<city> Hyderabad </city>
<state>Andhra Pradesh</state>
</address>
</student>
</students>"
);
PARKING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string input = "2012/07/08:00:00:00";
string input2 = "2012/07/08:23:59:00";
DateTime op = new DateTime();
DateTime op1 = new DateTime();
bool a1 = DateTime.TryParseExact(input, "yyyy/MM/dd:HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out op);
bool a2 = DateTime.TryParseExact(input2, "yyyy/MM/dd:HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out op1);
if (a1 == true && a2 == true)
{
TimeSpan h1 = (op1 - op);
double res = h1.TotalHours;
if (op<op1)
{
double a = (res - 3) ;
double n = 2;
double b = 0.00;
for (int h = 0; h < a; h++)
{
b = b + .50;
}
if (res > 3 && res < 24)
{
n = n + b;
Console.WriteLine(n );
}
else if (res >= 0 && res <= 3)
{
Console.WriteLine("2");
}
else if (res == 24)
Console.WriteLine("10");
else
Console.WriteLine("-3");
}
else
Console.WriteLine("-2");
}
else
Console.WriteLine("-1");
Console.Read();
}
}
}
public void fifth()
{
string str = "IX";
char[] ch = str.ToCharArray();
int flag=0,c=0,sum=0;
int[] a=new int[20];
foreach (char i in ch)
{
//Console.Write(i);
if (! (i == 'I' || i == 'V' || i == 'X' || i == 'L' || i == 'C' || i == 'D' || i == 'M'))
{
flag=1;
}
}
if (flag == 1)
{
}
else
{
foreach (char i in ch)
{
switch (i)
{
case 'I':
a[c] = 1;
c++;
break;
case 'V':
a[c] = 5;
c++;
break;
case 'X':
a[c] = 10;
c++;
break;
case 'L':
a[c] = 50;
c++;
break;
case 'C':
a[c] = 100;
c++;
break;
case 'D':
a[c] = 100;
c++;
break;
case 'M':
a[c] = 500;
c++;
break;
}
}
}
for(int i=0;i<c;i++)
{
if (a[i] >= a[i + 1])
{
sum = sum + a[i];
}
else
{
sum = sum - a[i];
}
}
Console.WriteLine(sum);
Console.ReadKey();
}
---------------------------------------------
int n = 123;
string op = "";
while (n != 0)
{
if (n >= 1000)
{
op += "M";
n = n - 1000;
}
else if (n >= 900 && n < 1000)
{
op += "C" + "M";
n = n - 900;
}
else if (n >= 500 && n < 900)
{
op += "D";
n = n - 500;
}
else if (n >= 400 && n < 500)
{
op += "C" + "D";
n = n - 400;
}
else if (n >= 100 && n < 400)
{
op += "C";
n = n - 100;
}
else if (n >= 90 && n < 100)
{
op += "X" + "C";
n = n - 90;
}
else if (n >= 50 && n < 90)
{
op += "L";
n = n - 50;
}
else if (n >= 40 && n < 50)
{
op += "X" + "L";
n = n - 40;
}
else if (n >= 10 && n < 40)
{
op += "X";
n = n - 10;
}
else if (n >= 9 && n < 10)
{
op += "I" + "X";
n = n - 9;
}
else if (n >= 5 && n < 9)
{
op += "V";
n = n - 5;
}
else if (n >= 4 && n < 5)
{
op += "I" + "V";
n = n - 4;
}
else if (n >= 1 && n <= 3)
{
op += "I";
n = n - 1;
}
}
Console.WriteLine(op);
Console.ReadLine();