《STL详解》解题报告
2024-08-26 21:55:54
看完发现文档缺页。。。。。。
3.5 菲波那契数
vector<int> v;
v.push_back();
v.push_back();
for(int i = ;i < ;++i)
v.push_back(v[i - ] + v[i - ]);
3.14 01 串 排 序
3.14.1 链接地址
http://acm.zjut.edu.cn/网上第 1204 题
3.14.2 题目内容
将 01 串首先按长度排序,长度相同时,按 1 的个数多少进行排序,1 的个数相同时再 按 ASCII 码值排序。 输入描述:输入数据中含有一些 01 串,01 串的长度不大于 256 个字符。 输出描述:重新排列 01 串的顺序,使得串按题目描述的方式排序。 输入样例
10011111
00001101
1010101
1
0
1100
输出样例
0
1
1100
1010101
00001101
10011111
struct myComp
{
bool operator ()(const string &a, const string &b)
{
if(a.size() != b.size())
return a.size() < b.size();
int numa = count(a.begin(), a.end(), '');
int numb = count(b.begin(), b.end(), '');
if(numa != numb)
return numa < numb;
return a < b;
}
}; int main()
{
multiset<string, myComp> m;
string s;
for(int i = ;i < ;++i)
{
cin >> s;
m.insert(s);
}
multiset<string, myComp> :: iterator it;
for(it = m.begin();it != m.end();++it)
cout << *it << endl;
return ;
}
3.15 排列对称串
3.15.1 链接地址
http://acm.zjut.edu.cn/网上第 1208 题
3.15.2 题目内容
字符串有些是对称的,有些是不对称的,请将那些对称的字符串按从小到大的顺序输 出。字符串先以长度论大小,如果长度相同,再以 ASCII 码值为排序标准。 输入描述:输入数据中含有一些字符串(1≤串长≤256)。 输出描述:根据每个字符串,输出对称的那些串,并且要求按从小到大的顺序输出。 输入样例
123321
123454321
123
321
sdfsdfd
121212
\\dd\\
输出样例
123321
\\dd\\
123454321
bool myComp(string &a, string &b)
{
if(a.size() != b.size())
return a.size() < b.size();
return a < b;
} int main()
{
string s, t;
vector<string> vs;
int i, j;
for(i = ;i < ;++i)
{
cin >> s;
t = s;
reverse(t.begin(), t.end());//反转
if(t == s)
vs.push_back(s);
}
sort(vs.begin(), vs.end(), myComp);
for(i = ;i < ;++i)
cout << vs[i] << endl;
return ;
}
4.4.7 编码
给定一个只包含“A”~“Z”的字符串,我们使用下面的方法给它编码: (1)将子字符串中的 k 个相同字符写成“kX ”,X 是子串中的字符。 (2)如果子串的长度是 1,那么“1”要忽略。
给定一个只包含“A”~“Z”的字符串,我们使用下面的方法给它编码: (1)将子字符串中的 k 个相同字符写成“kX ”,X 是子串中的字符。 (2)如果子串的长度是 1,那么“1”要忽略。
输入描述
第一行包含一个正整数 N(1≤N≤100),代表测试案例的个数。下面 N 行包含 N 个 字符串。每个字符串仅包含“A”~“Z”,且字符串的长度小于 100。
输出描述
对于每个测试案例,输出它的编码在单独一行上。
输入描述
2
第一行包含一个正整数 N(1≤N≤100),代表测试案例的个数。下面 N 行包含 N 个 字符串。每个字符串仅包含“A”~“Z”,且字符串的长度小于 100。
输出描述
对于每个测试案例,输出它的编码在单独一行上。
输入描述
2
ABC
ABBCCC
输出描述
ABC
ABC
A2B3C
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <stack>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <list>
#include <bitset> using namespace std; typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ; int main()
{
string s;
int n;
cin >> n;
while(n--)
{
string p;
cin >> s;
int num = ;
for(int i = ;i < s.size();++i)
{
if(s[i] == s[i - ])
num++;
else
{
if(num != )
p += num + '';
p += s[i - ];
num = ;
}
}
p += num + '';
p += s[s.size() - ];
cout << p << endl;
}
return ;
}
最新文章
- 图解Spark API
- Oracle:试图访问正在使用的事务临时表
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- 安装spf13-vim on Windows10
- jquery获取对象
- UVA 524
- 2015第28周六SVN和Git
- Linux中的ln
- 我的Python成长之路---第三天---Python基础(11)---2016年1月16日(雾霾)
- EXCEL随机密码生成函数
- CentOS 忘记 root password处理
- H5 内联 SVG
- python基础的输入字符串的格式化
- System V IPC 之信号量
- Linux备份策略(第二版)
- PowerPoint 中插入 Latex 公式
- Day05(fianl、抽象类、接口)
- 如何某个js文件中的 console
- Bootstrap &; Font Awesome 学习笔记
- 牛客网NOIP赛前集训营-普及组(第一场)C 括号