zoukankan      html  css  js  c++  java
  • 题目1168:字符串的查找删除(字符串操作)

    题目链接:http://ac.jobdu.com/problem.php?pid=1168

    详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

    参考代码:

    //
    //  1168 字符串的查找删除2.cpp
    //  Jobdu
    //
    //  Created by PengFei_Zheng on 25/04/2017.
    //  Copyright © 2017 PengFei_Zheng. All rights reserved.
    //
     
    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <cmath>
    #define MAX_SIZE 1001
     
    using namespace std;
     
    char str[MAX_SIZE];
     
    int main(){
        gets(str);
        string a = str;
        int lena = (int)a.size();
        for(int i = 0 ; i < lena ; i++){
            a[i] = tolower(a[i]);
        }
        while(gets(str)){
            string b = str;
            string c = b;
            int lenb = (int)b.size();
            for(int i = 0 ; i < lenb ; i++){
                b[i]=tolower(b[i]);
            }
            int pos = (int)b.find(a,0);
            while(pos!=string::npos){
                c.erase(pos,lena);
                b.erase(pos,lena);
                pos = (int)b.find(a,pos);
            }
            pos = (int)c.find(' ',0);
            while(pos!=string::npos){
                c.erase(pos,1);
                pos = (int)c.find(' ',0);
            }
            cout<<c<<endl;
        }
        return 0;
    }
    /**************************************************************
        Problem: 1168
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:0 ms
        Memory:1520 kb
    ****************************************************************/

    参考代码2:

    //
    //  1168 字符串的查找删除.cpp
    //  oj
    //
    //  Created by PengFei_Zheng on 03/04/2017.
    //  Copyright © 2017 PengFei_Zheng. All rights reserved.
    //
     
    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
     
     
    char c[1001];
    int match_len = 0;
    char ch;
     
    using namespace std;
     
    int main(){
         
        scanf("%s",c);
        int len = (int)strlen(c);//the length of pattern
        ch=getchar();//remove the space or return after input c
        while((ch=getchar())!=EOF){//get each char
            if(tolower(ch)==tolower(c[match_len])) {//find same character
                match_len++;//move index to next position
                if(match_len>=len) match_len=0;// reinitation ,if ch==c[len-1] then next i will be assigned len
            }
            else{
                if(match_len==0){//now position is not satisfy
                    if(ch!=' ') cout<<ch;//cout now char
                }
                else{//the array c is just right save the cahracter which is not cout to the screen
                    for(int k=0;k<match_len;k++){//now i keeps to the position max_match_length
                        cout<<(c[k]);
                    }
                    match_len=0;//reinitation i to 0
                    if(ch != ' ')  putchar(ch);//cout right now character
                }
            }
        }
         
    }
    /**************************************************************
        Problem: 1168
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:0 ms
        Memory:1520 kb
    ****************************************************************/
  • 相关阅读:
    jsp eclipse 创建jsp项目
    SQL Server 身份验证 登陆
    HUD 5086 Revenge of Segment Tree(递推)
    HDU 1700 Points on Cycle (几何 向量旋转)
    RocketMQ broker jvm 监控
    RocketMQ runbroker.sh 分析JVM启动参数
    问题:虚拟机老生代垃圾回收频繁出现
    空白行 ,空白
    eclipse find 两位数
    生成字母+数字6位字符串
  • 原文地址:https://www.cnblogs.com/zpfbuaa/p/6767977.html
Copyright © 2011-2022 走看看