【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甲級1126~1130|C++實現C++
- PAT甲級1032 Sharing
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- PAT甲級1030 Travel Plan
- 浙大PAT甲級考試
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- PAT甲級1023 Have Fun with Number
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- 20年春季甲級pat考試
- PAT甲級-1015. Reversible Primes (20)
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- PAT甲級真題1069 數字黑洞(巧妙解法)
- PAT甲級考試題庫題目分類
- 2024 秋季PAT認證甲級(題解A1-A4)
- PAT甲級-1140. Look-and-say Sequence (20)(模擬)
- 2021.9.12週六PAT甲級考試覆盤與總結
- 19年春季第二題 PAT甲級 1157 Anniversary(25 分)
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- 2020年7月第2題 PAT甲級真題 The Judger (25分)
- 夕甲甲——孔乙己之C++版C++
- A1084
- PAT(甲級)2020年秋季考試 7-1 Panda and PP Milk (20分)
- 【PAT乙級、C++】1024 科學計數法 (20分)C++
- PAT 乙級
- 【PTA甲級、C++簡單解答】1001 A+B Format (20分)C++ORM
- PTA甲級——Be Unique
- 2019年9月8日秋季PAT甲級題解-2-1161-Merging Linked Lists (25 分)
- PAT乙級1023
- 1021 Deepest Root(甲級)
- PAT1013數素數C++C++
- 【PAT乙級】1027 列印沙漏
- 【PAT乙級】1017 A除以B
- 【PAT乙級】1065 單身狗
- 【PAT乙級】1052 賣個萌