zoukankan      html  css  js  c++  java
  • csuoj 1394: Virus Replication

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1394

    1394: Virus Replication

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 135  Solved: 40
    [Submit][Status][Web Board]

    Description

    Input

    Output

    Sample Input

    AAAAA
    AGCGAA
    

    Sample Output

    3
    

    HINT

    Source

    分析;
    题目意思是找出在第一个串中第二个串没有出现的字母个数,要求从前往后遍历和从后往前遍历两次。

    AC代码:

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<queue>
     5 #include<iostream>
     6 #include<stack>
     7 #include<map>
     8 #include<string>
     9 using namespace std;
    10 char ch1[100050], ch2[100050];
    11 int main(){
    12     int n, a, b;
    13     while(~scanf("%s%s", ch1, ch2)){
    14         int l1 = strlen(ch1);
    15         int l2 = strlen(ch2);
    16         a = 0;
    17         b = l2-1;
    18         for(int i = 0; i < l1 && i < l2; i++){
    19             if(ch1[i] == ch2[i]){
    20                 a = i+1;
    21                 ch1[i] = '#'; //避免重复判断 
    22             }
    23             else
    24                 break;
    25         }
    26         for(int i = 1; i <= l1&&i <= l2;i++){
    27             if(ch1[l1-i] == ch2[l2-i]){
    28                 b = l2-i-1;
    29             }
    30             else
    31                 break; 
    32         }
    33         if(a > b)
    34             printf("0
    ");
    35         else
    36             printf("%d
    ", b-a+1);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    null和undefined的区别
    "NetworkError: 404 Not Found fontawesome-webfont.woff?v=4.0.3
    php字符串
    php数组
    Oracle 和 MySQL的区别(不完整)
    拦截器和过滤器的区别
    SpringMVC和Struts2的区别
    Redis的介绍
    SpringBoot入门(2)
    SpringBoot入门(1)
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4475375.html
Copyright © 2011-2022 走看看