Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 2 KB
using System;
using System.Text;
using System.IO;
namespace Keres
{
class Program
{
private string[] words = new string[2];
public Program()
{
StreamReader ins = new StreamReader("keres.be");
words[0] = ins.ReadLine();
words[1] = ins.ReadLine();
ins.Close();
ExpandByAsteriks();
SearchMatchingWord();
}
private void SearchMatchingWord()
{
StringBuilder word;
if( words[0].Length - words[1].Length != 0 ) {
word = new StringBuilder("NEM");
} else {
word = new StringBuilder();
for( int i=0; i<words[0].Length; i++ ) {
if( words[0][i] == '*' && words[1][i] == '*' ) {
} else if( words[0][i] == '?' && words[1][i] == '?' ) {
word.Append("a");
} else if( words[0][i] == '?' || words[1][i] == '?' ) {
word.Append( words[0][i] == '?' ? words[1][i] : words[0][i] );
} else if( words[0][i] == '*' || words[1][i] == '*' ) {
word.Append( words[0][i] == '*' ? words[1][i] : words[0][i] );
} else if( words[0][i] == words[1][i] ) {
word.Append( words[0][i] );
} else {
word = new StringBuilder("NEM");
break;
}
}
}
StreamWriter outs = new StreamWriter("keres.ki");
outs.WriteLine(word.ToString());
outs.Close();
}
private void ExpandByAsteriks()
{
int idx0 = words[0].LastIndexOf("*"), idx1 = words[1].LastIndexOf("*");
if( idx0 != -1 || idx1 != -1 ) {
StringBuilder sb0 = new StringBuilder();
for( int i=0; i<200-words[0].Length; i++ )
sb0.Append("*");
StringBuilder sb1 = new StringBuilder();
for( int i=0; i<200-words[1].Length; i++ )
sb1.Append("*");
if( idx0 == -1 ) {
words[0] = words[0].Insert( words[0].Length, sb0.ToString() );
} else {
words[0] = words[0].Insert( idx0, sb0.ToString() );
}
if( idx1 == -1 ) {
words[1] = words[1].Insert( words[1].Length, sb1.ToString() );
} else {
words[1] = words[1].Insert( idx1, sb1.ToString() );
}
}
}
public static void Main(string[] args)
{
new Program();
}
}
}