日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【简便解法】1084 Broken Keyboard (20 分)_16行代码AC

發布時間:2024/2/28 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【简便解法】1084 Broken Keyboard (20 分)_16行代码AC 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

立志用最少的代碼做最高效的表達


PAT甲級最優題解——>傳送門


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


題意:鍵盤上有一些鍵壞了, 給定字符串S1和S2,S1是本應該輸出的正確字符串,S2是實際輸出的字符串,問哪些鍵壞了。

算法邏輯:定義數組存放每個字母出現的次數,如果S1[i]!=S2[i] 并且這個字母時第一次出現,輸出即可。


#include<bits/stdc++.h> using namespace std; int a[300] = {0}; int main() {string s, s1; cin >> s >> s1;int i = 0, j = 0;while(i != s.size()) if(s[i] != s1[j]) {s[i] = tolower(s[i]);if(a[s[i]] == 0) cout << (char)toupper((s[i]));a[s[i++]]++;} else {i++; j++;}return 0; }

???????——愛所有人,信任少數人,不負任何人。

總結

以上是生活随笔為你收集整理的【简便解法】1084 Broken Keyboard (20 分)_16行代码AC的全部內容,希望文章能夠幫你解決所遇到的問題。

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