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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

發布時間:2024/2/28 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【简便解法】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的全部內容,希望文章能夠幫你解決所遇到的問題。

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