5 条题解

  • 0
    @ 2025-3-14 14:42:49
    /*
    思路分析
    思路一: 
        1. 用char c : str 遍历字符串 ,
        2. 比较c 与 ch 并选择输出
    思路二:
        1. 利用字符串容器特性 删除元素后输出
        ---remove() 方法可以删除满足条件的字符。 ==>移动到末尾
        ---erase() 方法可以删除字符串中的指定位置的字符,==> 将末尾的删掉
    
    #include <bits/stdc++.h>
    using namespace std;
    
    int main() 
    {
        string str;
        getline(cin , str);
        char ch;
        cin >> ch;
        for ( char c : str ) {
            if ( c != ch ) {
                cout << c;
            } else {
                continue;
            }
        }
        return 0;
    }
    
    #include <bits/stdc++.h>
    using namespace std;
    
    int main() 
    {
        string str;
        getline(cin , str);
        char ch;
        cin >> ch;
        //remove()将所有 ch(匹配的字符) 字符移动到字符串的末尾,
        //---并返回一个指向“新末尾”的迭代器。
        //str.erase(...) 删除从“新末尾”到原末尾的所有字符,
        //---从而实现删除指定字符的效果。
        str.erase(remove(str.begin() , str.end() , ch), str.end());
        for ( char c : str ) {
            cout << c;
        }
        return 0;
    }
    */
    
    • 0
      @ 2025-3-12 22:56:54
      #include <bits/stdc++.h>
      #define endl '\n'
      using namespace std; 
      using ll = long long;
      using ULL = unsigned long long;
      const int N = 1e6+5;
      
      string s;
      char c;
      inline void solve() {
          getline(cin,s);
          cin >> c;
          for (auto &i: s) {
              if (i != c)
                  cout << i ;
          } 
      }
      
      int main() { 
          ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
          int _ = 1; 
          //int _; cin >> _;
          while (_--) solve();
          return 0;
      }
      
      #include <bits/stdc++.h>
      #define endl '\n'
      using namespace std; 
      using ll = long long;
      using ULL = unsigned long long;
      const int N = 1e6+5;
      
      string s;
      char c;
      inline void solve() {
          getline(cin,s);
          cin >> c;
          s.erase(remove(s.begin(),s.end(),c), s.end());
          cout << s << endl;
      }
      
      int main() { 
          ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
          int _ = 1; 
          //int _; cin >> _;
          while (_--) solve();
          return 0;
      }
      
      • 0
        @ 2024-12-22 14:15:48
        #include <bits/stdc++.h>
        using namespace std;
        
        int main() {
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout.tie(nullptr);
            string str;
            char ch;
            string str2 = "";
            getline(cin, str);
            cin >> ch;
            for (int i = 0; i < str.size(); i++) {
                if (str[i] != ch) {
                    str2 += str[i];
                }
            }
            cout << str2 << endl;
        }
        
        • 0
          @ 2024-4-11 16:01:20
          #include
          using namespace std;
          
          int main()
          {
              string s;
              char c;
              getline(cin,s);
              cin>>c;
              int p=s.find(c);
              while(p != string::npos)
              {
          		s.erase(p,1);
          		p= s.find(c);
          	}
          	cout<<s;
          	return 0;
          }
          
          • 0
            @ 2024-4-11 15:21:23
            import java.util.HashMap;
            import java.util.Map;
            import java.util.Scanner;
            
            public class Main {
            
                public static void main(String[] args) {
                    Scanner sc = new Scanner(System.in);
            
                    String str = sc.nextLine();
                    char ch=sc.nextLine().charAt(0);
            
                    for (int i = 0; i < str.length(); i++) {
            
                        if (str.charAt(i)!=ch){
                            System.out.print(str.charAt(i));
                        }
            
                    }
            
                }
            }
            
            • 1

            信息

            ID
            75
            时间
            1000ms
            内存
            256MiB
            难度
            5
            标签
            递交数
            614
            已通过
            217
            上传者