| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
太搞笑了,为什么一定要搞这个格式呢
#include <iostream>
using namespace std;
int GetStepByPosi(int *a, int loop, int posi)
{
int pRst = posi;
for (int j = 0; j < loop; j++)
{
pRst = a[pRst] - 1;
if (pRst == posi)
return ++j;
}
return 0;
}
int input(int n)
{
int a[256], loop;
char inputStr[256], str[256], tempStr[256];
for (int i = 0; i < n; i++)
cin >> a[i];
while (cin >> loop, loop != 0)
{
getchar();
gets_s(inputStr);
for (int i = 0; i < n; i++)
str[i] = ' ';
for (int i = 0; i < (int)strlen(inputStr); i++)
str[i] = inputStr[i];
str[n] = '\0';
strcpy_s(tempStr, str);
for (int i = 0; i < n; i++)
{
int Step = GetStepByPosi(a, n, i);
int ploop = loop%Step;
int pRst = i;
for (int j = 0; j < ploop; j++)
pRst = a[pRst] - 1;
str[pRst] = tempStr[i];
}
cout << str << endl;
}
//我如何没料到原来是这个换行,非加不可
cout << endl;
return 1;
}
int main()
{
int n;
while (cin >> n, n != 0)
input(n);
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator