zoukankan      html  css  js  c++  java
  • 《STL详解》解题报告

    看完发现文档缺页。。。。。。

    3.5  菲波那契数

        vector<int> v;
        v.push_back(0);
        v.push_back(1);
        for(int i = 2;i < 46;++i)
            v.push_back(v[i - 1] + v[i - 2]);

    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(), '1');
            int numb = count(b.begin(), b.end(), '1');
            if(numa != numb)
                return numa < numb;
            return a < b;
        }
    };
    
    int main()
    {
        multiset<string, myComp> m;
        string s;
        for(int i = 0;i < 6;++i)
        {
            cin >> s;
            m.insert(s);
        }
        multiset<string, myComp> :: iterator it;
        for(it = m.begin();it != m.end();++it)
            cout << *it << endl;
        return 0;
    }

    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 = 0;i < 7;++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 = 0;i < 7;++i)
            cout << vs[i] << endl;
        return 0;
    }
    4.4.7  编码
    给定一个只包含“A”~“Z”的字符串,我们使用下面的方法给它编码: (1)将子字符串中的 k 个相同字符写成“kX ”,X 是子串中的字符。 (2)如果子串的长度是 1,那么“1”要忽略。
    输入描述
    第一行包含一个正整数 N(1≤N≤100),代表测试案例的个数。下面 N 行包含 N 个 字符串。每个字符串仅包含“A”~“Z”,且字符串的长度小于 100。
    输出描述
    对于每个测试案例,输出它的编码在单独一行上。
    输入描述
    2
    ABC
    ABBCCC
    输出描述
    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 = 1000005;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    
    int main()
    {
        string s;
        int n;
        cin >> n;
        while(n--)
        {
            string p;
            cin >> s;
            int num = 1;
            for(int i = 1;i < s.size();++i)
            {
                if(s[i] == s[i - 1])
                    num++;
                else
                {
                    if(num != 1)
                        p += num + '0';
                    p += s[i - 1];
                    num = 1;
                }
            }
            p += num + '0';
            p += s[s.size() - 1];
            cout << p << endl;
        }
        return 0;
    }
    现在所有的不幸都是以前不努力造成的。。。
  • 相关阅读:
    mysql 存在该记录则更新,不存在则插入的sql
    php计划任务的实现
    Dictionary<TKey,TValue>泛型封装
    win10家庭版 获取 syswow64权限
    发送带参数post请求
    visual studio自动向量化
    交叉编译
    opencv笔记meanshift&camshift
    [源码学习]调试Razor从哪里开始
    [转]官网下载Google Chrome离线安装包
  • 原文地址:https://www.cnblogs.com/shuizhidao/p/9272580.html
Copyright © 2011-2022 走看看