zoukankan      html  css  js  c++  java
  • 2018级程序能力实训第二次上机考试

    B. 最长无重复字符子串的长度

    维护一个不含重复字符的子串。每次子串右边界加入一个字符,若原子串中已经含有这个字符,向右移动左边界,直至重复字符离开子串。每次操作后更新maxx。不断重复该操作。

    #include <iostream>
    using namespace std;
    char s[1000];
    int cnt[1000];
    int main(){
        cin>>s;
        int l=0,r=0,len,maxx=0;
        while(r<strlen(s)){
            cnt[s[r]]++;
            while(s[r]!=''&&cnt[s[r]]>1){
                cnt[s[l]]--;
                ++l;
            }
            len=r-l+1;
            maxx=max(maxx,len);
            ++r;
        }
        cout<<maxx<<endl;
    }

    注意:

    1. cin、scanf读入字符数组遇到空格就停止。

    2. getline读取整行,包括前导、嵌入和末尾的空格。

    (1)   
    istream& getline (istream& is, string& str, char delim);
    (2)    
    istream& getline (istream& is, string& str);

    (1) getline把分隔符delim之前的字符全部保存在str中, 包括空格等; 此外分隔符delim也会被吸收但是不会被保存到str中。当delim没有显示的给出的时候, 默认为' '。

    C. Excel的字母横坐标

    进制转换。每一位从1开始。比如,A0=Z。

    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef long long ll;
    int a[111];
    
    int main(){
        ll n;
        cin>>n;
        int tmp=0;
        while(n){
            a[tmp++]=n%26;
            if(n%26==0){//处理每一位不为0;计算出为0就不进位
                a[tmp-1]=26;
                n-=26;
            }
            n/=26;
        }
        --tmp;
        while(tmp>=0){
            printf("%c",a[tmp]+'A'-1);
            --tmp;
        }
    }
  • 相关阅读:
    Python 猜数小程序(练习)
    Mysql 字符串日期互转
    MaxCompute 语句笔记
    数据仓库架构
    Python 比较两个字符串的相似度
    Python print
    Python简单计算器
    HashMap为什么线程不安全(死循环+数据丢失过程分析)
    浅谈ArrayList、Vector和LinkedList
    JAVA对象的浅克隆和深克隆
  • 原文地址:https://www.cnblogs.com/Maxx-el/p/13683172.html
Copyright © 2011-2022 走看看