您现在的位置是:主页 > news > 瀑布流响应式网站模板/互联网营销的优势

瀑布流响应式网站模板/互联网营销的优势

admin2025/6/15 20:43:41news

简介瀑布流响应式网站模板,互联网营销的优势,如何优化seo技巧,软件公司门户网站模板函数deletesushu删除head指向的链表中data值为素数的结点并返回删除结点后的新链表。例如链表8->7->5->3->2->9->6->4->1->0删除data值为素数得到的链表为:8->9->6->4->1>0。 说明:素数必须大于等于2。 &…

瀑布流响应式网站模板,互联网营销的优势,如何优化seo技巧,软件公司门户网站模板函数deletesushu删除head指向的链表中data值为素数的结点并返回删除结点后的新链表。例如链表8->7->5->3->2->9->6->4->1->0删除data值为素数得到的链表为:8->9->6->4->1>0。 说明:素数必须大于等于2。 &…

函数deletesushu删除head指向的链表中data值为素数的结点并返回删除结点后的新链表。例如链表8->7->5->3->2->9->6->4->1->0删除data值为素数得到的链表为:8->9->6->4->1>0。
说明:素数必须大于等于2。
(样例输入第一行为链表节点个数,第二行为从右至左的链表,样例输出为从左至右的链表)
样例输入:
5
5 4 3 2 1
样例输出:
4 1

#include<iostream>
#include<math.h>
using namespace std;
bool sushu(int n);
struct ListNode
{int data;ListNode *next;
};
ListNode *deletesushu(ListNode *head)
{ListNode *p , *t;int d;while(sushu(head->data)){head=head->next;}p=head;while(p->next){d=p->next->data;if(sushu(d)){t=p->next;p->next=p->next->next;delete t;continue;}p=p->next;}return head;
}
int main()
{struct ListNode *head=NULL,*t1,*t2,*t;int n;cin>>n;head = new ListNode;cin>>head->data;t2=head;for(int i=0;i<n-1;i++){t1=new ListNode;cin>>t1->data;t2->next=t1;t2=t1;}t2->next=NULL;head=deletesushu(head);t=head;while(t){cout<<t->data<<" ";t=t->next;}cout<<endl;return 0;
}
bool sushu(int n)
{if(n<2) {return 0;}if(n==2){return 1;}for(int i=2;i<=sqrt(n);i++){if(n%i==0){return 0;}}return 1;
}