Last active
August 29, 2015 14:21
-
-
Save nstanevski/c486169807d721092a61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
// Write a program that reads a string from the console, reverses it | |
// and prints the result back at the console. | |
class ReverseString | |
{ | |
static void Main(string[] args) | |
{ | |
char[] charArr = Console.ReadLine().ToCharArray(); | |
Array.Reverse(charArr); | |
string reversed = new string(charArr); | |
Console.WriteLine(reversed); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
/* | |
* Write a program that reads from the console a string of maximum 20 characters. | |
* If the length of the string is less than 20, the rest of the characters | |
* should be filled with *. Print the resulting string on the console. | |
*/ | |
class StringLength | |
{ | |
static void Main() | |
{ | |
string input = Console.ReadLine(); | |
StringBuilder sb; | |
if(input.Length>20){ | |
sb = new StringBuilder(input.Substring(0,20)); | |
}else{ | |
sb = new StringBuilder(input); | |
while(sb.Length<20){ | |
sb.Append('*'); | |
} | |
} | |
Console.WriteLine(sb.ToString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/* | |
* Write a program to find how many times a given string appears in a given text as substring. | |
* The text is given at the first input line. The search string is given at the second input line. | |
* The output is an integer number. Please ignore the character casing. Overlapping between | |
* occurrences is allowed. | |
*/ | |
class CountSubstringOccurences | |
{ | |
static void Main() | |
{ | |
string input = Console.ReadLine(); | |
string substring = Console.ReadLine(); | |
int numOccurences = 0; | |
int startIndex = 0; | |
while (input.IndexOf(substring, startIndex, StringComparison.OrdinalIgnoreCase) >= 0) | |
{ | |
numOccurences++; | |
startIndex = input.IndexOf(substring, startIndex, StringComparison.OrdinalIgnoreCase) + 1; | |
} | |
Console.WriteLine(numOccurences); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Text; | |
class TextFilter | |
{ | |
static void Main() | |
{ | |
string[] bannedWords = Console.ReadLine().Split(',').Select(p => p.Trim()).ToArray(); | |
string input = Console.ReadLine(); | |
StringBuilder textBuilder = new StringBuilder(input); | |
foreach (string bannedWord in bannedWords) | |
{ | |
string mask = new string('*', bannedWord.Length); | |
textBuilder.Replace(bannedWord, mask); | |
} | |
Console.WriteLine(textBuilder.ToString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/* | |
* Write a program that converts a string to a sequence of C# Unicode character literals. | |
*/ | |
class UnicodeCharacters | |
{ | |
static void Main() | |
{ | |
string input = Console.ReadLine(); | |
foreach (char ch in input) | |
Console.Write(@"\u{0}", ((int)ch).ToString("x4")); | |
Console.WriteLine(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
/* | |
* Write a program that extracts from a given text all palindromes, e.g. ABBA, lamal, exe | |
* and prints them on the console on a single line, separated by comma and space. | |
* Use spaces, commas, dots, question marks and exclamation marks as word delimiters. | |
* Print only unique palindromes, sorted lexicographically. | |
*/ | |
class Palindromes | |
{ | |
private static bool IsPalyndrome(string word) | |
{ | |
if (word.Length == 1) | |
return true; | |
int len = word.Length; | |
for(int i=0; i<len/2; i++){ | |
if(word[i] != word[len-i-1]) | |
return false; | |
} | |
return true; | |
} | |
static void Main() | |
{ | |
char[] delimiters = {' ', ',', '.', '?', '!' }; | |
SortedSet<string> palyndromes = new SortedSet<string>(); | |
List<string> words = Console.ReadLine(). | |
Split(delimiters, StringSplitOptions.RemoveEmptyEntries). | |
Select(p => p.Trim()).ToList(); | |
foreach(string word in words){ | |
if (IsPalyndrome(word)) | |
palyndromes.Add(word); | |
} | |
Console.WriteLine(string.Join(", ", palyndromes)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Threading; | |
//https://judge.softuni.bg/Contests/Practice/DownloadResource/452 | |
class LettersChangeNumbers | |
{ | |
static void Main() | |
{ | |
Thread.CurrentThread.CurrentCulture = | |
System.Globalization.CultureInfo.InvariantCulture; | |
char[] separators = {' ','\t' }; | |
string[] words = Console.ReadLine().Split(separators, | |
StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToArray(); | |
double sum=0.0; | |
foreach (string word in words) | |
{ | |
char prefix = word[0]; | |
char suffix = word[word.Length - 1]; | |
double number = double.Parse(word.Substring(1, word.Length - 2)); | |
if (Char.IsUpper(prefix)) | |
number /= 1.00*((int)prefix - (int)'A' + 1); | |
else | |
number *= 1.00 * ((int)prefix - (int)'a' + 1); | |
if (Char.IsUpper(suffix)) | |
number -= ((int)suffix - (int)'A' + 1); | |
else | |
number += ((int)suffix - (int)'a' + 1); | |
sum += number; | |
} | |
Console.WriteLine("{0:F2}", sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment