zoukankan      html  css  js  c++  java
  • PAT 1029 旧键盘(20)

    题目

    /*
     1029. 旧键盘(20)
     
     旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
     
     输入格式:
     
     输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。
     
     输出格式:
     
     按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。
     
     输入样例:
    7_This_is_a_test
    _hs_s_a_es
     输出样例:
     7TI
     */
    
    

    思路

    // str2 是 str1 的子集
    //
    // 先进行大小写转换操作
    // 根据map的特性,把字符插入到map中
    

    代码

    #include <cstdio>
    #include <map>
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main(){
    	
    	char str1[85],str2[85];
    	char str[85];
    	int ascii[200];
    	
    	cin >> str1 >> str2;
    	
    	memset(ascii, 0, sizeof(ascii));
    	memset(str, 0, sizeof(str));
    	
    	int length = (int)strlen(str1);
    	int cnt = 0;
    	for (int i = 0; i < length; ++i) {
    		if (str2[cnt] != str1[i]) {
    			char ch = str1[i];
    			// 转为大写
    			if (ch >= 'a' && ch <= 'z'){
    				ch += 'Z' - 'z';
    			}
    			// 插入到map中
    			if (ascii[ch] == 0) {
    				++ascii[ch];
    				int len = (int)strlen(str);
    				str[len] = ch;
    			}
    		}else{
    			++cnt;
    		}
    	}
    	
    	printf("%s
    ",str);
    	return 0;
    }
    
  • 相关阅读:
    xxx
    cdq分治入门--BZOJ1176: [Balkan2007]Mokia
    cdq分治入门--BZOJ3262: 陌上花开
    本月题量 171122晚-171222午
    cdq分治入门--BZOJ1492: [NOI2007]货币兑换Cash
    NOIP2017游记
    xx
    CF601D:Acyclic Organic Compounds
    LOJ#539. 「LibreOJ NOIP Round #1」旅游路线
    composer常用的一些命令参数说明
  • 原文地址:https://www.cnblogs.com/tangyikejun/p/4300395.html
Copyright © 2011-2022 走看看