7-87 A-B (20分)

在這裏插入圖片描述

分析

只輸出字符串A中字符串B不含有的字符,用一個map來記錄字符串B中出現的字符,然後輸出的時候只輸出字符串A中不在map裏的字符。
C++11 之for 新解 auto
C++11 auto遍歷
讓Dev支持C++11特性

代碼

#include<iostream>
#include<cstring>
#include<map>
using namespace std;


int main(){
	string a;getline(cin,a);//I love GPLT!  It's a fun game!
	string b;getline(cin,b);//aeiou
	map<char,int> m;  //用來記錄字符串b中包含的字符 
	
	for(auto t:b){
		m[t]++;
	} 
	
	for(int i=0;i<a.size();i++){
		if(m[a[i]]==0){  //輸出字符串A有而字符串B沒有的字符
			cout<<a[i];
		}
	}
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章