30pts求助玄关

P3612 [USACO17JAN] Secret Cow Code S

HEROBRINEH @ 2024-08-22 10:52:42


#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s1;
    cin>>s;
    s1=s;
    long long int n;
    scanf("&d",n);
    for(int i=1;i<=s.size();i++){
        s1=s1+s[s.size()]+s1;
        s1.erase(s1.size(),1);
        if(s1.size()>=n){
            cout<<s1[n]<<endl;
            break;
        }
    }
    return 0;
}

by dream_dad @ 2024-08-22 11:03:20

long long 改成unsigned long long试试


by HEROBRINEH @ 2024-08-22 11:05:35

@dream_dad 问题是还是 30分


by dream_dad @ 2024-08-22 11:14:48

@HEROBRINEH

#include<bits/stdc++.h>
using namespace std;
string s;
unsigned long long n;
unsigned long long l;
int main()
{
    cin>>s>>n;
    l=s.size();
    while(l<n)
    {
        string t="x";
        t+=s;
        t[0]=s[s.size()-1];
        s=s+t;
        s.erase(s.end() - 1);
        l=l*2;
    }
    printf("%c",s[n-1]);
}

by HEROBRINEH @ 2024-08-22 11:20:33

@dream_dad 额


by Inter12 @ 2024-08-22 11:24:58

@HEROBRINEH 我改了一下代码,在本地运行是没问题的,但在洛谷编译器上只输出D

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s1;
    cin>>s;
    s1=s;
    long long n;
    scanf("&d",n);
    for(int i=0;i<s.size();i++){
        s1=s1+s[i]+s1;
        s1.erase(s1.size()-1,1);
        if(s1.size()>=n){
            cout<<s1[n]<<'\n';
            break;
        }
    }
    return 0;
}

没改码风


by HEROBRINEH @ 2024-08-22 11:26:27

@Inter12 那为啥我输出的全是A啊?????(30pts)


by Inter12 @ 2024-08-22 11:30:39

@HEROBRINEH oops……不好意思说错了,但是下载了测试点后输出正确


|