Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Dynamic;
- using System.Collections.Generic;
- using System.Collections;
- public class Program
- {
- public static readonly string[] UPPERCASE = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
- public static readonly string[] LOWERCASE = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
- public static readonly int[] ODDNUMBERS = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63 };
- //is zero an even number?
- public static readonly int[] EVENNUMBERS = new int[] { 0,2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 };
- public static void Main()
- {
- Console.WriteLine("Please enter a sentence to weirdcase");
- string i = Console.ReadLine();
- Console.WriteLine(ToWeirdCase(i));
- }
- public static string ToWeirdCase(string userstring)
- {
- string weird = "";
- int ustrpos = 0;
- int size = 1;
- for(int i = 0; i < userstring.Length; i++)
- {
- char[] stringCharacters = userstring.ToCharArray();
- weird = weird + ToCorrectCase(stringCharacters[ustrpos].ToString(), ustrpos);
- ustrpos = ustrpos + 1;
- }
- return weird;
- }
- public static string ToCorrectCase(string l, int p)
- {
- string correctString = l;
- if(IsEvenNumber(p) && IsLowerCaseLetter(l)) {
- correctString = l;
- return correctString;
- }
- if(IsEvenNumber(p) && IsUpperCaseLetter(l)) {
- //we need to find out which uppercase character and get it's lowercase equivalent
- correctString = ToLowerCase(l);
- return correctString;
- }
- if(IsOddNumber(p) && IsLowerCaseLetter(l)) {
- //we need to find out which lowercase character and get it's uppercase equivalent
- correctString = ToUpperCase(l);
- return correctString;
- }
- if(IsOddNumber(p) && IsUpperCaseLetter(l)) {
- correctString = l;
- return correctString;
- }
- return correctString;
- }
- public static bool IsEvenNumber(int n)
- {
- bool isEven = true;
- for(int i = 0; i < EVENNUMBERS.Length; i++)
- {
- if(EVENNUMBERS[i] == n){
- isEven = true;
- break;
- }
- else{
- isEven = false;;
- }
- }
- return isEven;
- }
- public static bool IsOddNumber(int n)
- {
- bool isEven = true;
- for(int i = 0; i < ODDNUMBERS.Length; i++)
- {
- if(ODDNUMBERS[i] == n){
- isEven = false;
- break;
- }
- else{
- isEven = true;
- }
- }
- return !isEven;
- }
- public static bool IsUpperCaseLetter(string letter)
- {
- bool isUpperCase = true;
- for(int i = 0; i < UPPERCASE.Length; i++)
- {
- if(UPPERCASE[i] == letter){
- isUpperCase = true;
- break;
- }
- else{
- isUpperCase = false;;
- }
- }
- return isUpperCase;
- }
- public static bool IsLowerCaseLetter(string lietter)
- {
- bool isUpperCase = true;
- for(int i = 0; i < LOWERCASE.Length; i++)
- {
- if(LOWERCASE[i] == lietter){
- isUpperCase = true;
- break;
- }else {
- isUpperCase = false;
- }
- }
- return isUpperCase;
- }
- public static string ToUpperCase(string lttr)
- {
- //Which character is it?
- int characterArryIndex = 0;
- for(int i = 0; i < LOWERCASE.Length; i++)
- {
- if(LOWERCASE[i] == lttr)
- {
- characterArryIndex = i;
- break;
- }
- }
- //Now get the replacement
- return UPPERCASE[characterArryIndex];
- }
- public static string ToLowerCase(string lttr)
- {
- //Which character is it?
- int characterArryIndex = 0;
- for(int i = 0; i < UPPERCASE.Length; i++)
- {
- if(UPPERCASE[i] == lttr)
- {
- characterArryIndex = i;
- break;
- }
- }
- //Now get the replacement
- return LOWERCASE[characterArryIndex];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment