טוב, אז הנה הקוד הראשון שלי.
התוכנית מקבלת שתי מחרוזות כקלט (מניח שרק תווים באנגלית) ובודקת האם כל האותיות של המחרוזת הראשונה קיימות בשניה.
הנה הקוד. תגובות, הערות, הארות:
using System;
using System.Text;
public class stringFunctions {
public bool isAinB(String A, String B) {
A = A.ToLower();
B = B.ToLower();
int tmp;
int[] alphabet = new int[26];
for (int i=0; i tmp = ((int)B[i])-97;
//Console.WriteLine("tmp {0}, B[i] {1}", tmp, B[i]);
alphabet[tmp] = 1;
}
for (int i=0; i tmp = ((int)A[i])-97;
//Console.WriteLine("tmp {0}, A[i] {1}", tmp, A[i]);
if(alphabet[tmp] != 1) return false;
}
return true;
}
}
public class MyClass {
public static void Main() {
stringFunctions aa = new stringFunctions();
String str1, str2, result;
Console.WriteLine("What is the first string?");
str1 = Console.ReadLine();
Console.WriteLine("What is the second string?");
str2 = Console.ReadLine();
result = aa.isAinB(str1,str2).ToString();
Console.WriteLine(result);
Console.ReadKey(true);
}
[left]}[/left]