1. 程式人生 > 實用技巧 >L1-011 A-B

L1-011 A-B

L1-011A-B(20分)

本題要求你計算AB。不過麻煩的是,A和B都是字串 —— 即從字串A中把字串B所包含的字元全刪掉,剩下的字元組成的就是字串AB。

輸入格式:

輸入在2行中先後給出字串A和B。兩字串的長度都不超過1,並且保證每個字串都是由可見的ASCII碼和空白字元組成,最後以換行符結束。

輸出格式:

在一行中打印出AB的結果字串。

輸入樣例:

I love GPLT!  It's a fun game!
aeiou

輸出樣例:

I lv GPLT!  It's  fn gm!

一般來說,兩重迴圈可以搞定(沒有時間問題),不過需要注意一下那個字串的輸入問題,說實話,輸入輸出有時候經常出問題,需要仔細一點,特別關注一下;

//#include<bits/stdc++.h> 
#include <iostream>
#include <string>
#include <iomanip>        // 格式化輸入輸出 
#include <cmath>
#include <cstdlib> 
#include <vector>

using namespace std;

string str2 = "";

bool Identical(char ch,string str2) {
    for(int i = 0;i <= str2.length();i++)
        
if(ch == str2[i]) return false; return true; } int main() { string str1, str3 = ""; getline(cin,str1); getline(cin,str2); for(int i = 0;i < str1.length();i++) { if(Identical(str1[i],str2)) str3 += str1[i]; } cout<<str3<<endl;
return 0; }