String Typing CodeForces - 954B
生活随笔
收集整理的這篇文章主要介紹了
String Typing CodeForces - 954B
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:
給一個字符串,可以復制某一段字符,問最少需要多少步能將其輸出,比如abcabcd,先輸入abc然后再賦值abc再輸入d就只需要5步。
復制的這段字符 必須是從字符串的0位置開始復制的 ?而且只能粘貼一次 ?例abcabcabc ?輸出為7?
emm。。。
str.substr(i,j) 截取字符串str第i位置開始的長度為j的一段字符?
#include <bits/stdc++.h> //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 10010, INF = 0x7fffffff;int main() {int n;string str;cin>> n >> str;int res = n;for(int i=1; i<=n/2; i++)if(str.substr(0, i) == str.substr(i, i)) res = n - i + 1;cout<< res <<endl;return 0; }?
轉載于:https://www.cnblogs.com/WTSRUVF/p/9405096.html
總結
以上是生活随笔為你收集整理的String Typing CodeForces - 954B的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 基础:分分钟入门
- 下一篇: [sh]top添加到crontab不生效