Esempio n. 1
0
        static void RunCase(int CaseNum, System.IO.TextReader TR, System.IO.TextWriter TW)
        {
            char[]        Splits  = new char[] { ' ', '\t' };
            System.String Str     = "0" + TR.ReadLine();
            System.String BestStr = "";

            for (int i = 1; i < Str.Length; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    System.String NewStr = Str.Substring(0, j) + Str[i] + MinString(Str.Substring(j, i - j) + Str.Substring(i + 1));
                    if ((BestStr == "" || NewStr.CompareTo(BestStr) < 0) && NewStr.CompareTo(Str) > 0)
                    {
                        BestStr = NewStr;
                    }
                }
            }

            if (BestStr[0] == '0')
            {
                BestStr = BestStr.Substring(1);
            }

            System.String Result = "Case #" + (CaseNum + 1) + ": " + BestStr;
            if (TW == null)
            {
                System.Console.WriteLine(Result);
            }
            else
            {
                TW.WriteLine(Result);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Attempts to start the selected process. - BC
 /// </summary>
 /// <returns>Return value of the attempted command.</returns>
 public static int start(String program)
 {
     //MRM Get a list of all programs installed and basic information about them from Windows
     ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Product");
     ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
     ManagementObjectCollection collection = searcher.Get();
     //MRM The closest filename and the full path to the file
     String full = null;
     String closest = null;
     //MRM Loop through all the programs installed
     foreach (ManagementObject mObject in collection)
     {
         //MRM See if this is the correct program to be looking at
         if (((String)mObject["name"]).ToLower() == program.ToLower() && (String)mObject["InstallLocation"] != null)
         {
             //MRM Get the install location for the application since it is the one we are looking for
             String[] fileNames = System.IO.Directory.GetFiles((String)mObject["InstallLocation"]);
             foreach (String fileName in fileNames)
             {
                 //MRM Grab the actual filename to check
                 String[] fileSplit = fileName.Split('\\');
                 String file = fileSplit[fileSplit.Length - 1];
                 //MRM Make sure the file is executable and is not meant for updating or installing the application
                 if (file.Contains(".exe") && file.Substring(file.Length-4) == ".exe" && (!file.ToLower().Contains("update") && !file.ToLower().Contains("install")))
                 {
                     //MRM Replace all underscored with spaces to make it more towards the normal file naming convention
                     file = file.Replace("_", " ");
                     //MRM Get the first part of the file before any extension of . due to standard naming conventions
                     String[] fileNonTypes = file.Split('.');
                     file = fileNonTypes[0];
                     //MRM If there is no guess assume we are correct for now
                     if (closest == null)
                     {
                         full = fileName;
                         closest = file;
                     }
                     //MRM Else if the current file is closer than our previous guess, select that file
                     else if (Math.Abs(program.CompareTo(closest)) >= Math.Abs(program.CompareTo(file)))
                     {
                         full = fileName;
                         closest = file;
                     }
                 }
             }
             break;
         }
     }
     //MRM If we have found an adequte file to launch, launch the file.
     if (full != null)
     {
         //MRM Start a process with the correct information
         Process p = new Process();
         p.StartInfo.RedirectStandardOutput = false;
         p.StartInfo.RedirectStandardInput = false;
         p.StartInfo.FileName = full;
         p.Start();
         return 1;
     }
     return -1;
 }
Esempio n. 3
0
 public int SearchByName(List<Fund> Fundlist, String name)
 {
     //建议在抓取之后就按基金名称排序
     List<Fund> fundlist = new List<Fund>(Fundlist.ToArray());
     //按基金名称排序
     fundlist.Sort(compar);
     int start = 0;
     int end = fundlist.Count - 1;
     int mid = 0;
     //折半查找
     while (start <= end)
     {
         mid = (start + end) / 2;
         Console.WriteLine(mid + " " + start + " " + end);
         if (fundlist[mid].Name.Equals(name))
             break;
         else if (name.CompareTo(fundlist[mid].Name) < 0)
             end = mid - 1;
         else if (name.CompareTo(fundlist[mid].Name) > 0)
             start = mid + 1;
     }
     //原先的Fundlist该基金的位置
     int i = SearchByCode(Fundlist, fundlist[mid].Code);
     return i;
 }
Esempio n. 4
0
		public void setRelayState(String rState) {
			if(rState.CompareTo("on")==0) {
				relayState = true;
				computeLogic();
			} else if(rState.CompareTo("off") == 0) {
				relayState = false;
				computeLogic();
			}
		}
Esempio n. 5
0
		/// <summary>
		/// A method sending an event, which is here simply the argument + 1.
		/// Note that there is no return type to the method, because we use events to send
		/// information in WComp. Return values don't have to be used.
		/// </summary>
		public void input(String str) {
			if(str.CompareTo("True") == 0) {
				FireStringEvent("on");
			} else if(str.CompareTo("False") == 0) {
				FireStringEvent("off");
			} else {
				double d = Double.Parse(str);
				FireIntEvent((int)d);
				FireDoubleEvent(d);
			}
		}
Esempio n. 6
0
 /// <summary>
 /// get an image from resources (image resources are located in [current_dir]\Drawables and all have .png extension)
 /// </summary>
 /// <param name="imageName">image name without extension</param>
 /// <returns></returns>
 public static Image GetResourceImage(String imageName)
 {
     if (imageName.CompareTo("menu") == 0) imageName = "main";
     if (imageName.CompareTo("minimal") == 0) imageName = "scroll";
     Image image = new Image();
     System.IO.FileInfo fileInfo = new System.IO.FileInfo(Directory.GetCurrentDirectory() + "\\Drawables\\" + imageName + ".png");
     BitmapImage src = new BitmapImage();
     src.BeginInit();
     src.CacheOption = BitmapCacheOption.OnLoad;
     src.UriSource = new Uri(fileInfo.FullName, UriKind.Relative);
     src.EndInit();
     image.Source = src;
     return image;
 }
Esempio n. 7
0
        public Boolean IsFutureCode(String code)
        {
            if (code.CompareTo(this.KtbFuture_3yr_1.Code) == 0 ||
                code.CompareTo(this.KtbFuture_10yr_1.Code) == 0)
            {
                return true;
            }

            if (UnittestCodes.ContainsKey(code))
            {
                return true;
            }

            return false;
        }
Esempio n. 8
0
        public String customise(String text)
        {
            StringTokenizer st         = new StringTokenizer(text);
            List <String>   wordTokens = new List <String>();

            while (st.hasMoreTokens())
            {
                String word          = st.nextToken();
                String processedWord = process(word);
                if (processedWord.CompareTo("") != 0)
                {
                    wordTokens.Add(processedWord);
                }
            }
            String result = "";

            /*for (Iterator<String> iter = wordTokens.iterator(); iter.hasNext();) {
             *      result = result.concat(iter.next() + " ");
             * }*/
            foreach (var wordToken in wordTokens)
            {
                result += wordToken + " ";
            }
            return(result);
        }
Esempio n. 9
0
 public static void AddLock(String name)
 {
     lock (_masterLock)
     {
         if (Locks.ContainsKey(name))
         {
             throw new Exception(String.Format("Specified lock with name {0} already exists", name));
         }
         else
         {
             for (int i = 0; i < Keys.Count; i++)
             {
                 if (name.CompareTo(Keys[i]) < 0)
                 {
                     lock (Locks[Keys[i]])
                     {
                         Keys.Insert(i, name);
                     }
                     break;
                 }
             }
             if (!Keys.Contains(name))
             {
                 Keys.Add(name);
             }
             Locks.Add(name, new object());
         }
     }
 }
Esempio n. 10
0
        static Int32 artistCompare(String x, String y)
        {
            x = (x.ToLower().StartsWith("the ") ? x.ToLower().Replace("the ", "") : x);
            y = (y.ToLower().StartsWith("the ") ? y.ToLower().Replace("the ", "") : y);

            return x.CompareTo(y);
        }
Esempio n. 11
0
		/// <summary>
		/// A method sending an event, which is here simply the argument + 1.
		/// Note that there is no return type to the method, because we use events to send
		/// information in WComp. Return values don't have to be used.
		/// </summary>
		public void ChangeState(String stateStr) {
			
			if(stateStr.CompareTo("on")==0) {
				try{
				RPi.I2C.Net.I2CBus.instance.WriteBytes(0x12, new byte[] {0x00,0x01});
				FireStringEvent("on");
				}catch{}
			}
			if(stateStr.CompareTo("off")==0) {
				try{
				RPi.I2C.Net.I2CBus.instance.WriteBytes(0x12, new byte[] {0x00,0x00});
				FireStringEvent("off");
				}catch{}
			}
			
		}
Esempio n. 12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileName">Path and file name of log</param>
        /// <param name="debInf">Debug informations includng level, verbose, rotation information</param>
        public Debug(String fileName, ref DebugInformations debInf)
        {
            if (fileName.CompareTo("") == 0)
            {
                fileName = this._FileName;
            }

            Regex re = new Regex(@"\w+:\\\w+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);

            if (re.IsMatch(fileName))
            {

                this._Path = fileName.Substring(0, fileName.LastIndexOf('\\'));
                if (System.IO.Directory.Exists(this._Path))
                {
                    this._FileName = fileName;
                }
                else
                {
                    String exepath = Environment.GetCommandLineArgs()[0];
                    this._Path = exepath.Substring(0, exepath.LastIndexOf('\\'));
                    this._FileName = this._Path + "\\" + fileName;
                }
            }
            else
            {
                String exepath = Environment.GetCommandLineArgs()[0];
                this._Path = exepath.Substring(0, exepath.LastIndexOf('\\'));
                this._FileName = this._Path + "\\" + fileName;
            }

            this._DebugInfo = debInf;
            this._DebugInfo.Level = 1;
        }
Esempio n. 13
0
        public Boolean IsKtbCode(String code)
        {
            if (code.CompareTo(KtbSpot__3yr.Code) == 0||
                code.CompareTo(KtbSpot_5yr.Code) == 0||
                code.CompareTo(KtbSpot_10yr.Code) == 0)
            {
                return true;
            }

            if (this.UnittestCodes.ContainsKey(code))
            {
                return true;
            }

            return false;
        }
Esempio n. 14
0
 public static Boolean IsEmpty(String input)
 {
     if (input.CompareTo("empty") == 0)
     {
         return true;
     }
     return false;
 }
Esempio n. 15
0
 //两个函数返回的都是基金的在列表中的index
 public int SearchByCode(List<Fund> Fundlist,String code)
 {
     int start = 0;
     int end = Fundlist.Count - 1;
     int mid = 0;
     //折半查找
     while(start <= end){
         mid = (start + end)/2;
         Console.WriteLine(mid + " " + start + " " + end);
         if(Fundlist[mid].Code.Equals(code))
             return mid;
         else if(code.CompareTo(Fundlist[mid].Code) < 0)
             end = mid - 1;
         else if(code.CompareTo(Fundlist[mid].Code) > 0)
             start = mid + 1;
     }
     return -2;
 }
Esempio n. 16
0
        public override void UpdateUI(String strategyName, String header, String jsonData)
        {
            if (header.CompareTo(StrategyCommand.WAS_DIFF_DATA) == 0)
            {
                Serializer ser = new Serializer(typeof(Was_Diff_DataForUI));
                Was_Diff_DataForUI data = (Was_Diff_DataForUI)ser.Deserialize(jsonData);

                DrawDiffData(data);
            }
        }
 /// <summary>
 /// Date compare
 /// </summary>
 protected override Int32 OnCompare(String lhs, String rhs)
 {
     try
     {
         return DateTime.Parse(lhs).CompareTo(DateTime.Parse(rhs));
     }
     catch
     {
         return lhs.CompareTo(rhs);
     }
 }
Esempio n. 18
0
        /*
         * Determine if two ports are equal. Ports are equal if their
         * components are equal.
         *
         * @param o the other port to compare to.
         *
         * @return true if the ports are equal, false otherwise.
         **/
        public override bool Equals(System.Object o)
        {
            if (!(o is Port))
            {
                return(false);
            }

            Port port = (Port)o;

            return((this._creation == port._creation) && (this._id == port._id) && (_node.CompareTo(port._node) == 0));
        }
Esempio n. 19
0
 public static Type ConvertStringToType(String type)
 {
     if (type.CompareTo(Type.CurPrice) == 0)
     {
         return Type.CurPrice;
     }
     if (type.CompareTo(Type.BidPrice1) == 0)
     {
         return Type.BidPrice1;
     }
     if (type.CompareTo(Type.AskPrice1) == 0)
     {
         return Type.AskPrice1;
     }
     if (type.CompareTo(Type.BidCount1) == 0)
     {
         return Type.BidCount1;
     }
     if (type.CompareTo(Type.AskCount1) == 0)
     {
         return Type.AskCount1;
     }
     if (type.CompareTo(Type.Basis) == 0)
     {
         return Type.Basis;
     }
     return Type.Unknown;
 }
Esempio n. 20
0
        public Account GetAccount(String accountName)
        {
            logger.Debug("Get Account {0}", accountName);

            Account account = null;
            if (accountName.CompareTo("Sim") == 0)
            {
                account = AccountManager.Ins().CreateSimFOAccount();
            }
            else if (accountName.CompareTo("SimSpot") == 0)
            {
                account = AccountManager.Ins().CreateSimSpotAccount();
            }
            else if (accountName.CompareTo("SimBond") == 0)
            {
                account = AccountManager.Ins().CreateSimBondAccount();
            }
            else
            {
                account = AccountManager.Ins().GetAccount(accountName);
            }

            if (account == null)
            {
                logger.Error("Account problem ({0})", accountName);
                Util.KillWithNotice("Account problem");
                return null;
            }

            if (account.IsOccupied())
            {
                account = null;
                logger.Error("Account is in use({0})", accountName);
                Util.KillWithNotice("Account is in use");
                return null;
            }

            return account;
        }
Esempio n. 21
0
        /// <summary>
        /// Tells whether a file bears the table headers of GBase
        /// </summary>
        /// <param name="file">The name of the file to inspect</param>
        /// <param name="attr">You probably shouldn't change this...</param>
        /// <returns>True if the file bears a table header for GBase</returns>
        public bool FileIsTable(String file, String attr = "table")
        {
            _xmlIn.Open(file);  // Open the file

            if (attr.CompareTo(_xmlIn.GetValueFromUniqueTag("GBase", "Type")) == 0)     // See if the Type attribute has the value attr
            {
                _xmlIn.Close();     // Close the file
                return true;        // Yes it is
            }

            _xmlIn.Close();         // Otherwise... Close the file
            return false;           // No it's not
        }
Esempio n. 22
0
 public Int32 checkValues()
 {
     //Required Fields Validation
     Int32 isValid = 0;
     SLS.Validate.Alpha ctrlString = new SLS.Validate.Alpha();
     if (ctrlString.checkString(txtFN.Text) == 1)
     {
         isValid = 1;
         er2.Visible = true;
     }
     if (ctrlString.checkString(txtLN.Text) == 1)
     {
         isValid = 1;
         er1.Visible = true;
     }
     if (txtMN.Text != "")
     {
         if (ctrlString.checkString(txtMN.Text) == 1)
         {
             isValid = 1;
             er3.Visible = true;
         }
     }
     pass1 = txtPass.Text;
     pass2 = txtCPass.Text;
     if(pass1.CompareTo(pass2)==1)
     {
         MessageBox.Show("Password do not match!", "Error");
         er7.Visible = true;
         isValid = 1;
     }
     try
     {
         Convert.ToInt32(cmbAccount.SelectedIndex);
     }
     catch (Exception)
     {
         isValid = 1;
         er5.Visible = true;
     }
     try
     {
         Convert.ToInt32(cmbQuestion.SelectedIndex);
     }
     catch (Exception)
     {
         isValid = 1;
         er5.Visible = true;
     }
     return isValid;
 }
Esempio n. 23
0
 /* -1 -> if x < y;
  *  1 -> if x > y;
  *  0 -> if x == y; */
 public static int Compare(String str1, String str2)
 {
     if (str1.Length < str2.Length)
     {
         return -1;
     }
     else if (str1.Length > str2.Length)
     {
         return 1;
     }
     else
     {
         return str1.CompareTo(str2);
     }
 }
Esempio n. 24
0
        public Boolean returnUserName(String username, String password)
        {
            bool valid = false;
            if (username.CompareTo("") == 0 || password.CompareTo("")==0)
            {
                return valid;
            }
            else
            {
                using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
                {
                    valid = context.ValidateCredentials("cd-rosas\\" + username, password);
                }
                return valid;

            }
        }
        /**
         * @brief The class constructor
         * @param int n_id the id of the connection string
         * @param string str_connection_string the whole connection string
         * @param string str_user the user of the connection string
         * @param string str_pass the password of the user from the connection string
         * @param string str_catalog the catalog of the connection string
         * @param string str_data_source the data source of the connection string
         **/
        public ConnString(int n_id,
                            String str_connection_string,
                            String str_user,
                            String str_pass,
                            String str_catalog,
                            String str_data_source)
        {
            m_nId = n_id;

            if (str_connection_string.CompareTo("") == 0)
            {
                this.m_strConnectionString = CreateConnectionString(str_data_source, str_catalog, str_user, str_pass);
            }
            else
            {
                this.m_strConnectionString = str_connection_string;
            }

            this.m_strUser = str_user;
            this.m_strPass = str_pass;
            this.m_strCatalog = str_catalog;
            this.m_strDataSource = str_data_source;
        }
 public static System.String of(System.String left, System.String right)
 {
     return(left.CompareTo(right) < 0 ? right : left);
 }
Esempio n. 27
0
 private void setNameText(String text)
 {
     NameText.Content = text;
     if (text.CompareTo("") != 0 && NameBG.Opacity == 0)
     {
         DoubleAnimation anim1 = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(0.1));
         Storyboard board = new Storyboard();
         board.Children.Add(anim1);
         Storyboard.SetTarget(anim1, NameBG);
         Storyboard.SetTargetProperty(anim1, new PropertyPath("(Opacity)"));
         board.Completed += delegate
         {
             Animating = false;
         };
         Animating = true;
         board.Begin();
     }
     if (text.CompareTo("") == 0 && NameBG.Opacity == 1)
     {
         DoubleAnimation anim1 = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(0.1));
         Storyboard board = new Storyboard();
         board.Children.Add(anim1);
         Storyboard.SetTarget(anim1, NameBG);
         Storyboard.SetTargetProperty(anim1, new PropertyPath("(Opacity)"));
         board.Completed += delegate
         {
             Animating = false;
         };
         Animating = true;
         board.Begin();
     }
 }
Esempio n. 28
0
 private void setCharacterAlignment(String location)
 {
     if (location.CompareTo("right") == 0)
     {
         CharacterImage.HorizontalAlignment = HorizontalAlignment.Right;
     }
     if (location.CompareTo("left") == 0)
     {
         CharacterImage.HorizontalAlignment = HorizontalAlignment.Left;
     }
     if (location.CompareTo("center") == 0)
     {
         CharacterImage.HorizontalAlignment = HorizontalAlignment.Center;
     }
     else
     {
         CharacterImage.HorizontalAlignment = HorizontalAlignment.Right;
     }
 }
Esempio n. 29
0
 public Player makeNewPlayer(String type, Vector2 c,bool fromDup)
 {
     Player newP = null;
     if (type.CompareTo("normal") == 0)
     {
         players.Add(new NormalPlayer(texture, c, this, effect, fromDup));
     }
     else if (type.CompareTo("static") == 0)
     {
         players.Add(new StaticPlayer(staticTexture, c, this, effect, fromDup));
     }
     else if (type.CompareTo("duplicate") == 0)
     {
         players.Add(new DuplicatePlayer(dupTexture, c, this, effect, fromDup));
     }
     return newP;
 }
Esempio n. 30
0
    public static CList Init(String item)
    {
	CList newlist = new CList();
	int index = 0;

	if (item.CompareTo(String.Empty) == 0)
	    return newlist;                 //Empty CList is NIL
	if(item[0] == '('){
	    return InitMultiple(item, ref index);
	}
	else
	    newlist.Add(item);

	return newlist;
    }
Esempio n. 31
0
        private decimal GetTransactionAmount(String currency_s)
        {
            decimal ReturnValue = 0;

            currency_s = currency_s.ToLower();

            if (currency_s.CompareTo("transaction") == 0)
            {
                ReturnValue = parameters.Get("a_transaction_amount_n", situation.GetColumn(), situation.GetDepth()).ToDecimal();
            }
            else
            {
                if (currency_s.CompareTo("base") == 0)
                {
                    ReturnValue = parameters.Get("a_amount_in_base_currency_n", situation.GetColumn(), situation.GetDepth()).ToDecimal();
                }
                else
                {
                    if (currency_s.StartsWith("int"))
                    {
                        ReturnValue = parameters.Get("a_amount_in_intl_currency_n", situation.GetColumn(), situation.GetDepth()).ToDecimal();
                    }
                }
            }

            return ReturnValue;
        }
Esempio n. 32
0
        private String GetAccountingHierarchy(String param_accounting_hierarchy)
        {
            String ReturnValue;

            ReturnValue = "";

            if (param_accounting_hierarchy.CompareTo("STANDARD") != 0)
            {
                ReturnValue = ReturnValue + "Accounting Hierarchy: " + param_accounting_hierarchy;
            }

            return ReturnValue;
        }
Esempio n. 33
0
 private static Int32 CompareLines(String a, String b)
 {
     Char[] whitespace = {'\t', ' '};
     a = a.TrimStart(whitespace);
     b = b.TrimStart(whitespace);
     return a.CompareTo(b);
 }
Esempio n. 34
0
        /// <summary>
        /// 
        /// </summary>
        public Boolean CalulateLogic(String l)
        {
            try
            {
                string bit = "";
                while (l.Length > 1)
                {
                    bool v1 = (l[0].CompareTo('1') == 0) ? true : false;
                    bool v2 = (l[2].CompareTo('1') == 0) ? true : false;

                    switch (l[1])
                    {
                        case '&': bit = ((v1 && v2) ? "1" : "0");
                            break;
                        case '|': bit = ((v1 || v2) ? "1" : "0");
                            break;
                        case '!': bit = ((v1 != v2) ? "1" : "0");
                            break;
                    }

                    l = l.Remove(0, 3);//false && false != false && true || true;
                    l = bit + l;
                }
            }
            catch (Exception ex)
            {
                this._errorMessage = ex.Message;
            }
            return (l.CompareTo("1") == 0) ? true : false;
        }
Esempio n. 35
0
 public static int compareTo(this String str, String other)
 {
     return(str.CompareTo(other));
 }
Esempio n. 36
0
        /*
         * Determine if two PIDs are equal. PIDs are equal if their
         * components are equal.
         *
         * @param port the other PID to compare to.
         *
         * @return true if the PIDs are equal, false otherwise.
         **/
        public override bool Equals(System.Object o)
        {
            if (!(o is Pid))
            {
                return(false);
            }

            Pid pid = (Pid)o;

            return((this._creation == pid._creation) && (this._serial == pid._serial) && (this._id == pid._id) && (_node.CompareTo(pid._node) == 0));
        }
Esempio n. 37
0
 /// <summary> Compares this object with the specified object for order.
 ///
 ///  Ordering is determined by comparing attribute names (see
 /// {@link #getName() }) using the method compareTo() of the String class.
 ///
 ///
 /// </summary>
 /// <param name="attribute">  The LdapAttribute to be compared to this object.
 ///
 /// </param>
 /// <returns>            Returns a negative integer, zero, or a positive
 /// integer as this object is less than, equal to, or greater than the
 /// specified object.
 /// </returns>
 public virtual int CompareTo(System.Object attribute)
 {
     return(name.CompareTo(((LdapAttribute)attribute).name));
 }