字母

POJ1154 LETTERS(DFS)

醉酒当歌 提交于 2019-11-27 12:21:45
题意:给出一个n*m 的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母。问最多可以经过几个字母。 分析:一开始我错误的理解为,从(1,1)出发,最多能到达多少个字母,虽然样例对但WA声一片,再次审题后发现,题干的意思为从(1,1)出发找一条经过不重复字母 数最多的路径,因此就搜索,然后回溯就ok。 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 6 using namespace std; 7 8 const int dx[4]={-1,0,1,0}; 9 const int dy[4]={0,-1,0,1}; 10 11 char g[25][25]; 12 bool vis[25][25],num[205]; 13 int n,m,res; 14 15 inline void dfs(int ans,int x,int y) 16 { 17 res=max(ans,res); 18 for(int i=0;i<4;i++) 19 { 20 int nx=x+dx[i],ny=y+dy[i]; 21 if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&num[g[nx][ny]-'A']==false)

【PHP】数组按照字母排序

点点圈 提交于 2019-11-27 10:49:28
/** * 将数组按字母A-Z排序 * @return [type] [description] */ private function chartSort($list) { // $user=$this->user; $data = []; foreach ($list as $k => $v) { $v['letter'] = $this->getFirstChart($v['name']); if (empty($data[$v['letter']])) { $data[$v['letter']] = []; } $data[$v['letter']][] = $v; } $i = 0; foreach ($data as $k => $v) { $li[$i]['letter'] = $k; $li[$i]['list'] = $v; $i++; } sort($li); return $li; } /** * 返回取汉字的第一个字的首字母 * @param [type] $str [string] * @return [type] [strind] */ private function getFirstChart($str){ if( empty($str) ){ return ''; } $char=ord($str[0]); if( $char >= ord('A'

ASP.NET获取汉字拼音的首字母

柔情痞子 提交于 2019-11-27 07:03:13
#region GetChineseSpell获取汉字拼音的第一个字母 //获取汉字拼音的第一个字母 static public string GetChineseSpell(string strText) { int len = strText.Length; string myStr = ""; for (int i = 0; i < len; i++) { myStr += getSpell(strText.Substring(i, 1)); } return myStr; } static public string[] GetChineseSpell(string[] strText) { int len = strText.Length; string[] myStr = null; for (int i = 0; i < len; i++) { myStr[i] = getSpell(strText[i]); } return myStr; } static public string getSpell(string cnChar) { byte[] arrCN = Encoding.Default.GetBytes(cnChar); if (arrCN.Length > 1) { int area = (short)arrCN[0]; int pos =

比较continue和break

拥有回忆 提交于 2019-11-27 03:11:38
1 for letter in 'Python': 2 if letter == 'h': 3 continue 4 print('当前字母 :', letter) 5 6 运行结果: 7 当前字母 : P 8 当前字母 : y 9 当前字母 : t 10 当前字母 : o 11 当前字母 : n 12 13 14 for letter in 'Python': 15 if letter == 'h': 16 break 17 print('当前字母 :', letter) 18 19 运行结果: 20 当前字母 : P 21 当前字母 : y 22 当前字母 : t 来源: https://www.cnblogs.com/xuwinwin/p/11340850.html

中文首字母排序

隐身守侯 提交于 2019-11-27 03:04:20
要求按名字排序 List<user> list =new ArrayList<user>(); try { SAXReader reader=new SAXReader();//创建reder对象 用来读取xml Document doc=reader.read(new File("src/user.xml"));//读取xml文件 Element root=doc.getRootElement();//获取根节点 Iterator<?> it=root.elementIterator();//迭代器循环 while(it.hasNext()) { Element e=(Element) it.next();//获取子元素 Attribute id=e.attribute("id"); Element name=e.element("name"); Element dianhua=e.element("dianhua"); user u=new user(); u.setId(id.getValue()); u.setName(name.getText()); u.setDianhua(dianhua.getText()); list.add(u); } } catch (Exception e) { // TODO: handle exception } List<String>

LeetCode 242. Valid Anagram 题解(C++)

廉价感情. 提交于 2019-11-26 23:45:55
LeetCode 242. Valid Anagram 题解(C++) 题目描述 Given two strings s and t, write a function to determine if t is an anagram of s. 举例 s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false. 补充 You may assume the string contains only lowercase alphabets. 思路 首先先判断两个字符串的长度是否一样,若不一样则返回false; 定义一个包含26个整数的数组cNum,用于保存每个字母出现的次数,遍历字符串s,将每个字母出现的次数记录在数组cNum里; 再次遍历字符串t,若该字母对应的位置存储的值为0,则代表该字母为s没出现过或s出现过,但是已经被t之前的字母抵消,即该字母在s中无法找到想匹配的字母,返回false;若对应位置存储的值不为0,则值自减1,表示s中的该字母被抵消了一个。 代码 class Solution { public : bool isAnagram ( string s, string t) { if (s.size() != t.size()) { return false ; } int

PAT乙级1042

一世执手 提交于 2019-11-26 20:30:04
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805280817135616 题解 用数组 count 存储字母出现次数,数组下标代表字母,数组元素是次数。遍历字符串,统计各字母出现次数,最后遍历 count 寻找出现次数最多的字母。 // PAT BasicLevel 1042 // https://pintia.cn/problem-sets/994805260223102976/problems/994805280817135616 #include <iostream> #include <string> using namespace std; int main() { // 26个字母计数 int count[26]; fill(count,count+26,0); // 获取字符串 string str; getline(cin, str); // 字符串可能包含空格 // 统计字符出现次数 for(int i=0;i<str.length();++i){ if(isalpha(str[i])){ count[tolower(str[i])-'a']++; } } // 寻找出现最频繁的英文字母(其实可以在统计的时候进行) int maxCount=-1; int maxIndex

leetcode-917-仅仅反转字母-JavaScript版

房东的猫 提交于 2019-11-26 20:18:39
// 917 easy 仅仅反转字母 // // 给定一个字符串 S,返回 “反转后的” 字符串,其中不是字母的字符都保留在原地,而所有字母的位置发生反转。 // // 示例 1: // 输入:"ab-cd" // 输出:"dc-ba" // 示例 2: // 输入:"a-bC-dEf-ghIj" // 输出:"j-Ih-gfE-dCba" // 示例 3: // 输入:"Test1ng-Leet=code-Q!" // 输出:"Qedo1ct-eeLg=ntse-T!" /** * @param {string} S * @return {string} */ var reverseOnlyLetters = function(S) { let arr = S.split('') let prev = 0; let next = arr.length - 1; let reg = /[a-zA-Z]/ while(true){ if (prev >= next) { return arr.join('') } // 两个字符都是英文字母 if (reg.test(arr[prev]) && reg.test(arr[next])){ [arr[prev], arr[next]] = [arr[next], arr[prev]] prev++; next--; //

C#将首字母自动转换大写

一曲冷凌霜 提交于 2019-11-26 19:22:36
///上一篇PinYin设置的枚举 [System.FlagsAttribute] public enum PinYinOptions { None = 0, FirstLetterOnly = 1, //只转换拼音首字母,默认转换全部 TranslateUnknowWordToInterrogation = 1 << 1, //转换未知汉字为问号,默认不转换 EnableUnicodeLetter = 1 << 2,//保留非字母、非数字字符,默认不保留 } //转换需要用空格区分 CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; TextInfo text = cultureInfo.TextInfo; RandName = text.ToTitleCase(RandName); 转载于:https://www.cnblogs.com/xiaoshuai/archive/2010/06/05/1752364.html 来源: https://blog.csdn.net/weixin_30206617/article/details/99059015

LeetCode 409 Longest Palindrome

妖精的绣舞 提交于 2019-11-26 18:53:32
Problem: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Assume the length of given string will not exceed 1,010. Example: Input: "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7. Summary: 给出一个可能包含大写、小写字母的字符串,求用字符串中的字母可组成的最长回文串长度。此处大写、小写字母视为有区别。 Analysis: 1. 回文串包含两种形式:aba形式及aaa形式。在给出的字符串中,所有出现次数为偶数的字母都可以用为回文串中;若有出现次数为奇数的字母,则先将其包含的最大偶数次加入回文串长度中(即奇数次数减1)