leetcode-2-basic
解题思路:
题目本身挺简单的,考虑用set,判断每个单词的字母是不是属于同一个集合。需要注意的是:1)set的构造方法;2)单词可能是大小写混合的,不一定只是首字母大写;
3)break是跳出循环=。=switch写的时候要注意,不好用的话还是用if-else好了。
vector<string> findWords(vector<string>& words) {
char f[20] = {'q','w','e','r','t','y','u','i','o','p','Q','W','E','R','T','Y','U','I','O','P'};
set<char>first(f,f+20);
char s[18] = {'a','s','d','f','g','h','j','k','l','A','S','D','F','G','H','J','K','L'};
set<char>second(s, s+18);
char t[14] = {'z','x','c','v','b','n','m','Z','X','C','V','B','N','M'};
set<char>third(t, t+14);
vector<string>::iterator it;
string temp = "";
vector<string> result;
bool flag = true;
int i;
for (it = words.begin(); it != words.end(); it++) { temp = *it;
flag = true; if (temp.length() == 1) {
result.insert(result.end(), temp);
continue;
}
if (first.find(temp[0]) != first.end()) {
for (i = 1; i < temp.length(); i++) {
if (first.find(temp[i]) == first.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
}
else if (second.find(temp[0]) != second.end()) {
for (i = 1; i < temp.length(); i++) {
if (second.find(temp[i]) == second.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
}
else {
for (i = 1; i < temp.length(); i++) {
if (third.find(temp[i]) == third.end()) {
break;
}
}
if (i != temp.length()) {
flag = false;
continue;
}
} if (flag == true) {
result.insert(result.end(), temp);
}
}
return result;
}
leetcode-2-basic的更多相关文章
- [LeetCode] 224. Basic Calculator 基本计算器
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- [LeetCode] 227. Basic Calculator II 基本计算器 II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- [LeetCode] 772. Basic Calculator III 基本计算器之三
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- [LeetCode] 227. Basic Calculator II 基本计算器之二
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- LeetCode#227.Basic Calculator II
题目 Implement a basic calculator to evaluate a simple expression string. The expression string contai ...
- Java for LeetCode 227 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- Java for LeetCode 224 Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 224.Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- (medium)LeetCode 227.Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains ...
- leetcode 224. Basic Calculator 、227. Basic Calculator II
这种题都要设置一个符号位的变量 224. Basic Calculator 设置数值和符号两个变量,遇到左括号将数值和符号加进栈中 class Solution { public: int calcu ...
随机推荐
- [題解]luogu_P3205/BZOJ_1996 合唱隊
前言:基本上發題解的都是抄的題解所以 來源:題解 题目描述 为了在即将到来的晚会上有更好的演出效果,作为AAA合唱队负责人的小A需要将合唱队的人根据他们的身高排出一个队形.假定合唱队一共N个人,第i个 ...
- awk一些简单命令
最简单地说, AWK 是一种用于处理文本的编程语言工具.AWK 在很多方面类似于 shell 编程语言,尽管 AWK 具有完全属于其本身的语法. 尽管操作可能会很复杂,但命令的语法始终是: awk ' ...
- File "<stdin>" , line 1
写了一个hello.py,仅有一句,print 'hello world', 运行 Python hello.py 出错,提示: File "<stdin>" , li ...
- Java设计模式开篇
在所有的设计模式开篇中,总是说一个好的架构,或多或少都会有设计模式的出现.当然或多或少也会使用设计模式的相关原则: SOLID+迪米尔原则 1.优化代码的第一步:单一职责原则 S:单一职责链原则:英文 ...
- [BZOJ1047][HAOI2007]理想的正方形 二维单调队列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 我们对每矩阵的一列维护一个大小为$n$的单调队列,队中元素为矩阵中元素.然后扫描每一 ...
- 指定ip地址登陆服务器
[root@localhost ~]# cat /etc/hosts.allow ## hosts.allow This file contains access rules which are ...
- 严重:The web application [web01] appears to have started a thread named ...
Tomcat报错 严重:The web application [web01] appears to have started a thread named [PooledThread-1] but ...
- Node.js 打造实时多人游戏框架
在 Node.js 如火如荼发展的今天,我们已经可以用它来做各种各样的事情.前段时间UP主参加了极客松活动,在这次活动中我们意在做出一款让“低头族”能够更多交流的游戏,核心功能便是 Lan Party ...
- NBUT 1115 Cirno's Trick (水)
题意: 给出多个double数,去掉其最小的和最大的,再对余下的求均值. 思路: 再输入时将最大和最小去掉,顺便统计非最值的和,输出时除一下个数即可. #include <bits/stdc++ ...
- 关于HTML5中Video标签无法播放mp4的解决办法
1.首先先排除掉代码问题.路径问题.浏览器不支持问题等常规问题,这些问题另行百度. <video width="500px" height="300px" ...