求看代码

P3612 [USACO17JAN] Secret Cow Code S

Zhe8468 @ 2020-08-10 14:11:25

#include <bits/stdc++.h>
using namespace std;
int n;string str;
string rotate(string x){
    int len = x.length();
    if(len>n) return x;
    string add = "";
    add+=x[len-1];
    for(int i=0;i<len-1;i++){
        add+=x[i];
    }
    rotate(x+add);
}
int main()
{
    cin>>str;
    cin>>n;
    string res = rotate(str);
    cout<<res[n-1]<<endl;
    return 0;
}

by DeusExMachina @ 2020-08-10 14:24:16

这东西是干什么用的,有什么用?没给题我分析不出来代码qaq


by Zhe8468 @ 2020-08-10 14:29:55

@TheRedKiller_ P3612


by DeusExMachina @ 2020-08-10 14:43:38

@Zhe8468

#include <bits/stdc++.h>
using namespace std;
int n;string str;
int main()
{
    cin>>str;
    cin>>n;
    while(str.size()<n)
    {
        int l=str.size();
        string nres="";nres+=str[l-1];
        for(int i=0;i<=l-2;i++) nres+=str[i];
        str+=nres;
    }
    cout<<str[n-1]<<endl;
    return 0;
}

试试?样例过了


by Zhe8468 @ 2020-08-10 14:58:46

@TheRedKiller_ 我想用递归可以吗


|