zoukankan      html  css  js  c++  java
  • L1-011 A-B

    本题要求你计算AB。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串AB。

    输入格式:

    输入在2行中先后给出字符串A和B。两字符串的长度都不超过104​​,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。

    输出格式:

    在一行中打印出AB的结果字符串。

    输入样例:

    I love GPLT!  It's a fun game!
    aeiou
    

    输出样例:

    I lv GPLT!  It's  fn gm!
    
     
    思路:这个题目有两种解法,推荐用解法二写......
     
    解法一:直接两层循环比较字符后输出,暴力解就完事儿了,
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 int main()
     5 {
     6     char num[10001];
     7     char num1[10001];
     8     gets(num);
     9     gets(num1);
    10     int len=strlen(num);
    11     int len1=strlen(num1);
    12     for(int i=0;i<len;i++)
    13     {
    14         int flag=0;
    15         for(int j=0;j<len1;j++)
    16         {
    17             if(num[i]==num1[j])
    18             {
    19               flag=1;
    20               break;
    21             }
    22         }
    23             if(flag==0)
    24             printf("%c",num[i]);
    25     }
    26     printf("
    ");
    27     return 0;
    28 }

    解法二:建立一个用字符当下标的数组进行标记,再输出,

     1 #include<iostream>
     2 #include<cstring>
     3 using namespace std;
     4 int main()
     5 {
     6     int book[300];
     7     memset(book,0,sizeof(book));
     8     string str1;
     9     getline(cin,str1);
    10     string str2;
    11     getline(cin,str2);
    12     for(int i=0;i<str2.size();i++)
    13     book[str2[i]-' ']=1;//标记
    14     for(int i=0;i<str1.size();i++)
    15     {
    16         if(book[str1[i]-' ']==0)
    17         cout<<str1[i];
    18     }
    19     return 0;
    20 }
    大佬见笑,,
  • 相关阅读:
    Python 集合
    Python sorted()
    CodeForces 508C Anya and Ghosts
    CodeForces 496B Secret Combination
    CodeForces 483B Friends and Presents
    CodeForces 490C Hacking Cypher
    CodeForces 483C Diverse Permutation
    CodeForces 478C Table Decorations
    CodeForces 454C Little Pony and Expected Maximum
    CodeForces 313C Ilya and Matrix
  • 原文地址:https://www.cnblogs.com/xwl3109377858/p/10292405.html
Copyright © 2011-2022 走看看