[Codeforces]1005 B. Delete from the Left

題目URL: http://codeforces.com/contest/1005/problem/B

簡單的從後往前掃,注意不一樣就break,重點是我看了其他人都用reverse的函式再從頭開始掃(我又學到一招了),反正我是用手刻,至於快或慢......影響不大,看個人習慣~細節注意就行

自我補充reverse:
string a;
reverse( a.begin() , a.end() );

#include<bits/stdc++.h>
using namespace std;
char str1[200005],str2[200005];
int main()
{
    cin >> str1;
    cin >> str2;
    int len1=strlen(str1) , len2=strlen(str2);
    int tot=len1+len2,total=0,deter=0;
    for(int i=len1-1,j=len2-1;i>=0,j>=0;i--,j--)
    {
        if(str1[i]!=str2[j])
        {
            total=len1-1-i+len2-1-j;
            deter=1;
        }
        break;
    }
        if(deter==1)
            cout << tot-total << endl;
        else if(total==0)
            cout << abs(len1-len2) << endl;
    return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP