【PAT甲級A1084】Broken Keyboard (20分)(c++)
1084 Broken Keyboard (20分)
作者:CHEN, Yue
單位:浙江大學
程式碼長度限制:16 KB
時間限制:400 ms
記憶體限制:64 MB
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
題意:
第一行輸入準備打的字串,第二行輸入用鍵盤打出的字串,
找出壞掉的鍵盤,用大寫輸出。
思路:
將兩行字串全部改為大寫,然後遍歷第一行字串,若和第二行對不上,則該字元為破壞的鍵盤字元,並將第一行中的這個字元全部刪除,直到遍歷結束。(注意對比時上下兩行的對齊)。
參考程式碼:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
string s1, s2, str;
cin >> s1 >> s2;
transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
for (int i = 0; i < s1.length();) {
if (s2[i] != s1[i]) {
char temp = s1[i];
str += s1[i];
while (s1.find(temp) != string::npos)
s1.erase(s1.find(temp), 1);
} else i++;
}
cout << str;
return 0;
}
如有錯誤,歡迎指正
相關文章
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- PAT甲級考試題庫題目分類
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- PAT甲級1126~1130|C++實現C++
- PAT甲級-1005. Spell It Right (20)各位之和
- PAT甲級1023 Have Fun with Number
- 2024 秋季PAT認證甲級(題解A1-A4)
- 【PAT乙級、C++】1024 科學計數法 (20分)C++
- 【PTA甲級、C++簡單解答】1001 A+B Format (20分)C++ORM
- 2021.9.12週六PAT甲級考試覆盤與總結
- PAT甲級-1010. Radix (25)進位制
- PAT甲級-1012. The Best Rank (25)並列排序排序
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- PAT 乙級 1094 谷歌的招聘 (20分)---【素數 字串】谷歌字串
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- PTA甲級 1076 Forwards on Weibo (30分)Forward
- PAT乙 1041 考試座位號 (15分)(C C++)C++
- PAT乙級1004 成績排名 (20分)(C語言版)及解析C語言
- 【PAT乙級】1048 數字加密加密
- Broken pipe
- PAT1013數素數C++C++
- oracle ENABLE=BROKENOracle
- PAT乙級——1093(字串匹配)Java實現字串匹配Java
- PAT乙級比賽-互評成績計算
- iOS:Managing the KeyboardiOS
- C++ 測試框架 GoogleTest 初學者入門篇 甲C++框架Go
- Iterm2 keyboard shortcut
- Keyboard Shortcuts for the KDE Desktop
- java.net.SocketException: Broken pipeJavaException
- C++分類C++
- L1-056 猜數字 (20分) C++C++
- PAT 2023 冬 乙 方格填數
- PAT (Advanced Level) Practice 1149 Dangerous Goods Packaging (25分)Go