其中有一个测试案例没有通过,testcase3有可能是边界输入问题,虽然已经判断但是没有考虑到题目中的情况,欢迎各位提出问题
#include<iostream>
using namespace std;
#include<string>
typedef struct Node
{
char data;
Node*next;
}List;
int main()
{
int m;
int count=0;
string s1;
getline(cin,s1);
m=s1[0]-'0';
char t='0';
t=s1[1];
int test=s1[1]-'0';
if (t!=' ')
{
return -1;
}
int len=s1.length();
List*head=new List();
head->next=NULL;
head->data=s1[2];
++count;
List*p2=head;
for (int i=3;i<len;i++)
{
if (s1[i]!=' ')
{
count++;
List*q=new List();
q->data=s1[i];
q->next=NULL;
p2->next=q;
p2=q;
}
}
if (count<=1||count>=20)
{
delete head;
return -1;
}
p2->next=head;
if (count==1)
{
cout<<head->data<<endl;
delete head;
return 0;
}
List*p1=head;
int flag=0;
flag++;
List*pre=new List();//听取博友的意见,此处修改了下
while(count!=1)
{
if (flag==m)
{
cout<<p1->data<<" ";
pre->next=p1->next;
p1=p1->next;
--count;
flag=0;
flag++;
}
else
{
pre=p1;
p1=p1->next;
flag++;
}
}
cout<<p1->data<<endl;
delete head;
delete pre;
return 0;
}