帮做2个C++的编程啊

来源:百度知道 编辑:UC知道 时间:2024/05/16 13:13:25
1.17个人围成一圈,编号为1-17,从第1号开始报数,报到3的倍数的人离开,一直数下去,直到最后只剩下一个人。求此人编号
2.编写程序,判断所输入的字符串是否是回文串(aabcc是回文串,而aabbc就不是)。
Int strjust(const char * str);当是回文串时。返回正数;否则返回负数;

1.
#include <iostream>

using namespace std;

const int people = 17;

struct outt
{
outt *next;
bool go;
int num;
};

int main( )
{
outt *p, *head;
int i, n = 0, t = 0;
head = new outt;
head->go = true;
head->num = 1;
p = head;
for ( i = 1; i < people; i++ )
{
outt *s = new outt;
p->next = s;
s->go = true;
s->num = i + 1;
p = s;
}
p->next = head;
p = head;
while ( n != people - 1 )
{
t++;
if ( t % 3 == 0 )
{
if ( p->go )
{
n++;
p->go = false;
}
else
t--;
}
p = p->next;
}
p = head;
while ( !p->go )
{
p = p->next;
}
cout << p->num;
return 0;
}

2.
#include <iostream>

usi