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 ...
随机推荐
- 洛谷1005(dp)
1.不要贪,缩小区间去dp就好. 2.预处理指数. 3.__int128可还行. #include <cstdio> #include <cctype> #include &l ...
- Codeforces Round #497 (Div. 2) A. Romaji
Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...
- MyBatis中时间格式的映射问题
简单地说,就是Java的Date类可以直接映射到Mysql的TIMESTAMP或者是DATETIME(按道理应该是映射成DATE的) 具体的看这两篇博客吧: 1. MySql中TIMESTAMP和DA ...
- java中的线程安全是什么?什么叫线程安全?什么叫不安全?
java中的线程安全是什么: 就是线程同步的意思,就是当一个程序对一个线程安全的方法或者语句进行访问的时候,其他的不能再对他进行操作了,必须等到这次访问结束以后才能对这个线程安全的方法进行访问 什么叫 ...
- Java-IDEA环境搭建swagger
1.项目POM导入包(使用Maven管理的代码) 2.POM文件导入包 <dependencyManagement> <dependencies> <dependency ...
- hihocoder1080 更为复杂的买卖房屋姿势
思路: 线段树区间修改,需要使用两个懒标记set和add.处理好两个标记的优先级即可(set之前的set和add是没有作用的). 实现: #include <bits/stdc++.h> ...
- SPOJ1716 GSS3(线段树)
题意 Sol 会了GSS1,GSS3就比较无脑了 直接加个单点修改即可,然后update一下 /* */ #include<cstdio> #include<cstring> ...
- JS权威指南-概述学习
<script src="/javascripts/application.js" type="text/javascript" charset=&quo ...
- iOS 如何解决并发请求时,只接受最后一个请求返回的结果
大致意思是 虽然NSOperation 的cancel 并不能取消请求,但是可以对这个NSOperation进行标记. 当cancel 属性是YES时,表明 NSOperation虽然已经执行,并 ...
- 【MATLAB 从零到进阶】day2 矩阵 数组
访问矩阵元素 >> A=[1,2,3;4,5,6;7,8,9]; >> x=A(2,3)% 双下标访问 x = 6 >> x=A(2)% 单下标访问 x = 4 单 ...