Advertisement
abasar

string 9/3

Mar 9th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.87 KB | None | 0 0
  1. //#1
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace ConsoleApplication1524
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string st = Console.ReadLine();
  14.             int k = st.Length - 2;
  15.             Console.WriteLine(st.Substring(0, 1));
  16.             Console.WriteLine(st.Substring(st.Length - 1));
  17.             Console.WriteLine(st.Substring(st.Length / 2, 1));
  18.             Console.WriteLine(st.Substring(0, st.Length / 2));
  19.             Console.WriteLine(st.Substring(st.Length/2));
  20.             Console.WriteLine(st.Substring(0, 3));
  21.             Console.WriteLine(st.Substring(st.Length - 3));
  22.             Console.WriteLine(st.Substring(0, k));
  23.             Console.WriteLine(st.Substring(st.Length - k));
  24.             st.Replace("go", "went");
  25.         }
  26.     }
  27. }
  28.  
  29. //#2
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Linq;
  33. using System.Text;
  34.  
  35. namespace ConsoleApplication1524
  36. {
  37.     class Program
  38.     {
  39.         static void Main(string[] args)
  40.         {
  41.             string ktovet = Console.ReadLine();
  42.             string city = Console.ReadLine();
  43.             int index = ktovet.IndexOf(city);
  44.             if (index >= 0)
  45.                ktovet = ktovet.Remove(index, city.Length);
  46.             Console.WriteLine(ktovet);
  47.         }
  48.     }
  49. }
  50.  
  51. //#3
  52. using System;
  53. using System.Collections.Generic;
  54. using System.Linq;
  55. using System.Text;
  56.  
  57. namespace ConsoleApplication1524
  58. {
  59.     class Program
  60.     {
  61.         static void Main(string[] args)
  62.         {
  63.             string st = "aal aiv isn't kam";
  64.             int i = 2, counter = 0;
  65.             if (st[0] == 'a')
  66.                 counter++;
  67.             while (i < st.Length)
  68.             {
  69.                 if (st[i] == 'a' && st[i-1] == ' ')
  70.                     counter++;
  71.                 i++;
  72.             }
  73.             Console.WriteLine(counter);
  74.         }
  75.     }
  76. }
  77.  
  78. //#4
  79. using System;
  80. using System.Collections.Generic;
  81. using System.Linq;
  82. using System.Text;
  83.  
  84. namespace ConsoleApplication1524
  85. {
  86.     class Program
  87.     {
  88.         static void Main(string[] args)
  89.         {
  90.             string st = "aaa aia isn'a kaa";
  91.             int i = 2, counter = 0;
  92.             if (st[st.Length - 1] == 'a')
  93.                 counter++;
  94.             while (i < st.Length - 2)
  95.             {
  96.                 if (st[i] == 'a' && st[i+1] == ' ')
  97.                     counter++;
  98.                 i++;
  99.             }
  100.             Console.WriteLine(counter);
  101.         }
  102.     }
  103. }
  104.  
  105.  
  106. //#5
  107. using System;
  108. using System.Collections.Generic;
  109. using System.Linq;
  110. using System.Text;
  111.  
  112. namespace ConsoleApplication1524
  113. {
  114.     class Program
  115.     {
  116.         static void Main(string[] args)
  117.         {
  118.             string st = "aaY aia isn'Y kaa";
  119.             int i = 2, counter = 0;
  120.             if (st[st.Length - 1] == 'Y')
  121.                 counter++;
  122.             while (i < st.Length - 2)
  123.             {
  124.                 if (st[i] == 'Y' && st[i+1] == ' ')
  125.                     counter++;
  126.                 i++;
  127.             }
  128.             Console.WriteLine(counter);
  129.         }
  130.     }
  131. }
  132.  
  133. //#6
  134. using System;
  135. using System.Collections.Generic;
  136. using System.Linq;
  137. using System.Text;
  138.  
  139. namespace ConsoleApplication1524
  140. {
  141.     class Program
  142.     {
  143.         static void Main(string[] args)
  144.         {
  145.             string st = "galnivmagniv", x = Console.ReadLine();
  146.             int mone = 0;
  147.             while (st.IndexOf(x) > 0)
  148.             {
  149.                 mone++;
  150.                 st = st.Remove(st.IndexOf(x), x.Length);
  151.             }
  152.             Console.WriteLine(mone);
  153.         }
  154.     }
  155. }
  156.  
  157. //#7
  158. using System;
  159. using System.Collections.Generic;
  160. using System.Linq;
  161. using System.Text;
  162.  
  163. namespace ConsoleApplication1524
  164. {
  165.     class Program
  166.     {
  167.         static void Main(string[] args)
  168.         {
  169.             string st = "galnivmagniv", x = Console.ReadLine(), y = Console.ReadLine();
  170.             int index = st.IndexOf(x);
  171.             st = st.Insert(index, y);
  172.             index += y.Length;
  173.             st = st.Remove(index, x.Length);
  174.             Console.WriteLine(st);
  175.         }
  176.     }
  177. }
  178.  
  179. //#8
  180. using System;
  181. using System.Collections.Generic;
  182. using System.Linq;
  183. using System.Text;
  184.  
  185. namespace ConsoleApplication1524
  186. {
  187.     class Program
  188.     {
  189.         static void Main(string[] args)
  190.         {
  191.             string[] arr = { "gal", "liv", "magniv", "meod", "photography" };
  192.             int mone = 0;
  193.             for (int i = 0; i < arr.Length - 1; i++)
  194.             {
  195.                 string last = arr[i], first=arr[i+1];
  196.                 last = last.Substring(last.Length - 1, 1);
  197.                 first = first.Substring(0, 1);
  198.                 if (last == first)
  199.                     mone++;
  200.             }
  201.             Console.WriteLine(mone);
  202.         }
  203.     }
  204. }
  205.  
  206. //#9
  207. Go to this link the table is there - http://i.snag.gy/5S5Qu.jpg
  208.  
  209. //#10
  210. using System;
  211. using System.Collections.Generic;
  212. using System.Linq;
  213. using System.Text;
  214.  
  215. namespace ConsoleApplication1524
  216. {
  217.     class Program
  218.     {
  219.         static void Main(string[] args)
  220.         {
  221.             string st = "galnivmagniv@photography.com";
  222.             int index = st.IndexOf("@");
  223.             if (index < 0)
  224.                 Console.WriteLine("Doesn't exist");
  225.             else
  226.             {
  227.                 st = st.Remove(index);
  228.                 Console.WriteLine(st);
  229.             }
  230.         }
  231.     }
  232. }
  233.  
  234. //#11
  235. using System;
  236. using System.Collections.Generic;
  237. using System.Linq;
  238. using System.Text;
  239.  
  240. namespace ConsoleApplication1524
  241. {
  242.     class Program
  243.     {
  244.         //א
  245.         static string Sod0(string st)
  246.         {
  247.             string hafuh = "";
  248.             for (int i = 0; i < st.Length; i++)
  249.             {
  250.                 hafuh += st[st.Length - i - 1];
  251.             }
  252.             return hafuh;
  253.         }
  254.  
  255.         //ב
  256.         static bool Sod1(string st)
  257.         {
  258.             return st.Equals(Sod0(st));
  259.         }
  260.  
  261.         static void Main(string[] args)
  262.         {
  263.             string st = Console.ReadLine();
  264.             int i = 0;
  265.             while (st != "exit")
  266.             {
  267.                 if (!Sod1(st))
  268.                     Console.WriteLine(Sod0(st));
  269.                 else
  270.                     i++;
  271.                 st = Console.ReadLine();
  272.             }
  273.             Console.WriteLine(i);
  274.         }
  275.     }
  276. }
  277.  
  278. //#12
  279. using System;
  280. using System.Collections.Generic;
  281. using System.Linq;
  282. using System.Text;
  283.  
  284. namespace ConsoleApplication1524
  285. {
  286.     class Program
  287.     {
  288.         static bool Hukit(string pass)
  289.         {
  290.             if (pass.Length != 6)
  291.                 return false;
  292.             int mone = 0;
  293.             for (int i = 0; i < pass.Length; i++)
  294.                 if (Char.IsLetter(pass[i]))
  295.                     mone++;
  296.             if (mone < 3)
  297.                 return false;
  298.  
  299.             return true;
  300.         }
  301.  
  302.         static void Main(string[] args)
  303.         {
  304.             string st = Console.ReadLine();
  305.             if (Hukit(st))
  306.                 Console.WriteLine("WELLCOME");
  307.             else
  308.             {
  309.                 while (!Hukit(st))
  310.                 {
  311.                     Console.WriteLine("ERROR, INSERT ANOTHER PASSWORD");
  312.                     st = Console.ReadLine();
  313.                 }
  314.                 Console.WriteLine("WELLCOME");
  315.             }
  316.         }
  317.     }
  318. }
  319.  
  320. //#13
  321. using System;
  322. using System.Collections.Generic;
  323. using System.Linq;
  324. using System.Text;
  325. using System.Threading.Tasks;
  326.  
  327. namespace ConsoleApplication2
  328. {
  329.     class Program
  330.     {
  331.         static string Spaces(string st)
  332.         {
  333.             while (st.IndexOf("  ") != -1)
  334.             {
  335.                 st = st.Replace("  ", " ");
  336.             }
  337.             return st;
  338.         }
  339.         static void Main(string[] args)
  340.         {
  341.             Console.WriteLine(Spaces("a  a a a    a   a  a     a a"));
  342.         }
  343.     }
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement