日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1084. Broken Keyboard (20)

發布時間:2023/12/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1084. Broken Keyboard (20) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目例如以下:

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.

Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.

Input Specification:

Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or "_" (representing the space). It is guaranteed that both strings are non-empty.

Output Specification:

For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.

Sample Input: 7_This_is_a_test _hs_s_a_es Sample Output: 7TI


題目的實質就是從A字符串中找到全部B中沒有的。然后輸出。注意要把字母轉為大寫,而且反復的僅僅輸出一次。輸出順序為與從前到后探測到的順序同樣。

由于不區分大寫和小寫,所以我們使用一個map存儲全部實際輸出的字符,然后遍歷期望的字符串,假設遍歷到的字符是字母,先轉為大寫,然后去map查詢,假設查不到則說明是要輸出的。而且存儲map,這樣就保證了不反復輸出,也滿足了輸出順序和大寫。

代碼例如以下:

#include <iostream> #include <string> #include <map> #include <stdio.h>using namespace std;int main() {string wanner,input;cin >> wanner >> input;map<char,bool> inputMap;for(int i = 0; i < input.length(); i++){input[i] = isalpha(input[i]) ? toupper(input[i]) : input[i];inputMap[input[i]] = true;}for(int i = 0; i < wanner.length(); i++){char c = wanner[i];c = isalpha(c) ? toupper(c) : c;if(inputMap.find(c) == inputMap.end()){inputMap[c] = true;printf("%c",c);}}return 0; }

總結

以上是生活随笔為你收集整理的1084. Broken Keyboard (20)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。