Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace sms2007
- {
- class Program
- {
- struct sms
- {
- public string szo;
- }
- static sms[] szavak = new sms[600];
- static int x=0;
- static void Main(string[] args)
- {
- string osszes = "abcdefghijklmonpqrstuvwxyz";
- char[] abc = new char[26];
- for (int i = 0; i < 26; i++)
- {
- abc[i] = osszes[i];
- }
- Console.Write("1. feladat: Adjon meg egy betűt: ");
- string be = Console.ReadLine();
- char betu = Convert.ToChar(be);
- for (int i = 0; i < 26; i++)
- {
- if (betu == abc[i])
- {
- if (i >= 0 && i <= 2) Console.WriteLine("2"); else { };
- if (i >= 3 && i <= 5) Console.WriteLine("3"); else { };
- if (i >= 6 && i <= 8) Console.WriteLine("4"); else { };
- if (i >= 9 && i <= 11) Console.WriteLine("5"); else { };
- if (i >= 12 && i <= 14) Console.WriteLine("6"); else { };
- if (i >= 15 && i <= 18) Console.WriteLine("7"); else { };
- if (i >= 19 && i <= 21) Console.WriteLine("8"); else { };
- if (i >= 22 && i <= 25) Console.WriteLine("9"); else { };
- }
- }
- Console.Write("2. feladat: Kérem a szót: ");
- string b = Console.ReadLine();
- string ki = "";
- for (int i = 0; i < b.Length; i++)
- {
- for (int j = 0; j < 26; j++)
- {
- if (b[i] == abc[j])
- {
- if (j >= 0 && j <= 2) ki+="2"; else { };
- if (j >= 3 && j <= 5) ki+="3"; else { };
- if (j >= 6 && j <= 8) ki+="4"; else { };
- if (j >= 9 && j <= 11) ki+="5"; else { };
- if (j >= 12 && j <= 14) ki+="6"; else { };
- if (j >= 15 && j <= 18) ki+="7"; else { };
- if (j >= 19 && j <= 21) ki+="8"; else { };
- if (j >= 22 && j <= 25) ki+="9"; else { };
- }
- }
- }
- Console.WriteLine(ki);
- Console.WriteLine("3. feladat: Az adatok beolvasása a szavak.txt fájlból.");
- StreamReader sr = new StreamReader("szavak.txt");
- string sor = sr.ReadLine();
- while (sor != null)
- {
- szavak[x].szo=sor;
- x++;
- sor = sr.ReadLine();
- }
- Console.WriteLine(x);
- Console.Write("4. feladat: A leghosszabb tárolt szó és hossza: ");
- int maxhossz = 0;
- string hosszuszo="";
- for (int i = 0; i < x; i++)
- {
- if (szavak[i].szo.Length > maxhossz) maxhossz = szavak[i].szo.Length; else { };
- }
- for (int i = 0; i < x; i++)
- {
- if (szavak[i].szo.Length == maxhossz) hosszuszo = szavak[i].szo; else { };
- }
- Console.WriteLine("{0}, {1} karakter", hosszuszo, maxhossz);
- Console.Write("5. feladat: Rövid szavak száma: ");
- int darab = 0;
- for (int i = 0; i < x; i++)
- {
- if (szavak[i].szo.Length <= 5) darab++; else { };
- }
- Console.WriteLine(darab);
- Console.WriteLine("6. feladat: Az adatok kiírása a kodok.txt állományba.");
- FileStream fs = new FileStream("kodok.txt", FileMode.Create);
- StreamWriter sw = new StreamWriter(fs);
- string[] szamsor = new string[x];
- for (int h = 0; h < x; h++)
- {
- for (int i = 0; i < szavak[h].szo.Length; i++)
- {
- for (int j = 0; j < 26; j++)
- {
- if (szavak[h].szo[i] == abc[j])
- {
- if (j >= 0 && j <= 2) szamsor[h] += "2"; else { };
- if (j >= 3 && j <= 5) szamsor[h] += "3"; else { };
- if (j >= 6 && j <= 8) szamsor[h] += "4"; else { };
- if (j >= 9 && j <= 11) szamsor[h] += "5"; else { };
- if (j >= 12 && j <= 14) szamsor[h] += "6"; else { };
- if (j >= 15 && j <= 18) szamsor[h] += "7"; else { };
- if (j >= 19 && j <= 21) szamsor[h] += "8"; else { };
- if (j >= 22 && j <= 25) szamsor[h] += "9"; else { };
- }
- }
- }
- }
- for (int i = 0; i < x; i++)
- {
- sw.WriteLine(szamsor[i]);
- Console.WriteLine(szamsor[i]);
- }
- Console.WriteLine(szamsor[523]);
- Console.Write("7. feladat: Kérem a számsort: ");
- string azon = Console.ReadLine();
- for (int i = 0; i < x; i++)
- {
- if (szamsor[i] == azon) Console.WriteLine(szavak[i].szo); else { };
- }
- sr.Close();
- sw.Close();
- fs.Close();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement