2007_TCHS_tournament-gamma_round3
来源:互联网 发布:加拿大硕士奖学金知乎 编辑:程序博客网 时间:2024/05/29 18:26
250分题目
Problem Statement
????
All the alphabetical keys on your keyboard are broken. Given a string word, return the minimal number of keys you must repair to be able to type word.
Definition
????
Class:
BrokenKeyboardRepair
Method:
minimalNumberOfKeys
Parameters:
string
Returns:
int
Method signature:
int minimalNumberOfKeys(string word)
(be sure your method is public)
????
Constraints
-
word will contain between 1 and 50 characters, inclusive.
-
word will contain only lowercase letters ('a'-'z').
Examples
0)
????
"coder"
Returns: 5
You have to repair the following keys: 'c', 'd', 'e', 'o', 'r'.
1)
????
"hello"
Returns: 4
You have to repair the following keys: 'e', 'h', 'l', 'o'.
2)
????
"abracadabra"
Returns: 5
You have to repair the following keys: 'a', 'b', 'c', 'd', 'r'.
//简单说就是要计算一个字符串中不同字符的个数
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
class BrokenKeyboardRepair
{
public:
vector <char> w_str;
int minimalNumberOfKeys(string word)
{
string p_word=""+word[0];
int returns_r=1;
for(int i =1 ;i<word.size();i++) if ( isInIt(p_word,word[i])==false ) returns_r++
return returns_r;
}
bool isInIt(string &s,char c)
{
for(int i =0 ;i<s.size();i++) if (s[i]==c) return true; else { s=s+c;return false;}
}
};
房间得分最高的一个选手
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <utility>
#include <sstream>
#include <cctype>
#include <cmath>
#include <ctime>
using namespace std;
#define foreach(it,c) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define print(A,N) copy(A,A+N,ostream_iterator<int>(cout,""))
class BrokenKeyboardRepair
{
public:
int minimalNumberOfKeys(string);
};
int BrokenKeyboardRepair::minimalNumberOfKeys(string word)
{
set<char> res;
for(int i=0; i<word.size();i++)
res.insert(word[i]);
return res.size();
}
Problem Statement
????
All the alphabetical keys on your keyboard are broken. Given a string word, return the minimal number of keys you must repair to be able to type word.
Definition
????
Class:
BrokenKeyboardRepair
Method:
minimalNumberOfKeys
Parameters:
string
Returns:
int
Method signature:
int minimalNumberOfKeys(string word)
(be sure your method is public)
????
Constraints
-
word will contain between 1 and 50 characters, inclusive.
-
word will contain only lowercase letters ('a'-'z').
Examples
0)
????
"coder"
Returns: 5
You have to repair the following keys: 'c', 'd', 'e', 'o', 'r'.
1)
????
"hello"
Returns: 4
You have to repair the following keys: 'e', 'h', 'l', 'o'.
2)
????
"abracadabra"
Returns: 5
You have to repair the following keys: 'a', 'b', 'c', 'd', 'r'.
//简单说就是要计算一个字符串中不同字符的个数
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
class BrokenKeyboardRepair
{
public:
vector <char> w_str;
int minimalNumberOfKeys(string word)
{
string p_word=""+word[0];
int returns_r=1;
for(int i =1 ;i<word.size();i++) if ( isInIt(p_word,word[i])==false ) returns_r++
return returns_r;
}
bool isInIt(string &s,char c)
{
for(int i =0 ;i<s.size();i++) if (s[i]==c) return true; else { s=s+c;return false;}
}
};
房间得分最高的一个选手
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <utility>
#include <sstream>
#include <cctype>
#include <cmath>
#include <ctime>
using namespace std;
#define foreach(it,c) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define print(A,N) copy(A,A+N,ostream_iterator<int>(cout,""))
class BrokenKeyboardRepair
{
public:
int minimalNumberOfKeys(string);
};
int BrokenKeyboardRepair::minimalNumberOfKeys(string word)
{
set<char> res;
for(int i=0; i<word.size();i++)
res.insert(word[i]);
return res.size();
}
- 2007_TCHS_tournament-gamma_round3
- 2007_TCHS_tournament-gamma_round3 -500
- 2007
- 2007
- 2007
- 2007
- 2007
- 2007
- 2007
- 2007
- SIGMOD 2007&VLDB 2007
- 展望 2007
- 新年--2007
- 望2007
- hello 2007
- 2007cy
- 2007学习计划
- 写给2007
- Joel Spolsky给计算机系学生的建议 及一些个人看法
- The balance between the number of specs and the rate of coverage
- javascript 一些屏蔽功能代码
- 女孩纹身全过程(组图)
- 脚本与XSL的结合及应用
- 2007_TCHS_tournament-gamma_round3
- (转载)菜鸟拼杀ZOJ心得:[ZZ]递归深度优先搜索
- C#面象对象学习:委托(delegate)
- 浅析.Net下的多线程编程
- NET组件编程 PropertyAttribute和EventAttribute
- javascript的IE和Firefox兼容性汇编
- FMS客户端 ActionScript NetConnection类
- Java技术资料
- 破解部分密码的方法