1 solutions

  • 0
    @ 2025-8-15 15:57:39

    手搓链表就能过(不会就用STL的链表)

    /*********************************************************************
      程序名: K. [GESP202406 三级] 移位
      作者: 田朗语(tianlangyufirst)
      日期: 2025-08-15 15:26:27
      说明: 
     *********************************************************************/
    #include <iostream>
    using std::cin,std::cout;
    
    int n;
    struct node{//链表主体
    	char ch;
    	node *next;//用单向链表就够
    }*head,*r,*p;//头指针,尾指针,访问指针
    
    int main() {
    	std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	
    	cin>>n;
    	head=new node;
    	head->ch='A';
    	head->next=nullptr;
    	r=head;
    	
    	for(int i=1;i<26;++i){
    		p=new node;
    		p->ch='A'+i;
    		p->next=nullptr;
    		r->next=p;
    		r=p;
    	}
    	
    	r->next=head;
    	
    	p=head;
    	for(int i=0;i<n;++i) p=p->next;//移动指针到输出起始位置
    	for(int i=0;i<26;++i,p=p->next){
    		cout<<p->ch;
    	}
    	//释放内存
    	r->next=nullptr;
    	p=head;
    	while(p!=nullptr){
    		node *tmp=p;
    		p=p->next;
    		delete tmp;
    	}
    	
    	return 0;
    }
    
    
    • 1

    Information

    ID
    15590
    Time
    1000ms
    Memory
    512MiB
    Difficulty
    1
    Tags
    # Submissions
    24
    Accepted
    12
    Uploaded By