zoukankan      html  css  js  c++  java
  • PAT 1084. Broken Keyboard

    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

    分析

    用了C语言中的标准函数库中的strchr()函数可以实现查找字符串中的某个字符。
    
    头文件: #include <string.h>
    
    函数原型:char *strchr(const char *s, int c);
    
    函数说明:从左向右,在字符串s中查找字符c首次出现的位置,如果找到返回c在s中的位置(指针),否则返回NULL
    

    代码如下.

    #include<iostream>
    #include<algorithm>
    #include<cctype> 
    #include<string.h>
    using namespace std;
    int main(){
        char input1[81],input2[81],broken[81]={0};
        scanf("%s%s",&input1,&input2);
        int t1=0,t2=0,t=0;
        while(input2[t2]!=''){
             if(input1[t1]!=input2[t2]){
                if(isalpha(input1[t1]))
                   input1[t1]=toupper(input1[t1]); 
                if(!strchr(broken,input1[t1]))
                   broken[t++]=input1[t1];
                t1++;   
             }   
             else{
                t1++; t2++;
             }
        }
        while(input1[t1]!=''){
              if(isalpha(input1[t1]))
                 input1[t1]=toupper(input1[t1]);
              if(!strchr(broken,input1[t1]))
                 broken[t++]=input1[t1];
              t1++;       
        }
        printf("%s",broken);
        return 0;
    }
    
  • 相关阅读:
    react篇章-React State(状态)
    react篇章-React 组件-复合组件
    react篇章-React 组件-向组件传递参数
    react篇章-React 组件-ES6 class 来定义一个组件
    React篇章-React 组件
    复习常用算法_冒泡算法
    项目管理小结(如何做好一个百万级项目甚至千万级别的项目)
    AOP切点切面内容
    Spring 框架
    Spring MVC 框架
  • 原文地址:https://www.cnblogs.com/A-Little-Nut/p/8409603.html
Copyright © 2011-2022 走看看