65,184
社区成员




int main(void)
{
char s[50];
int i, j, r, k, n, l, len;
scanf("%s%d", s, &k);
len = strlen(s);
if(0 == len % k) n = strlen(s) / k;
else n = strlen(s) / k + 1;
len = n*k + 1;
char *t = malloc(len);
l = 0;
for (i = 0; i < k; i++)
{
r = i;
for (j = 0; j < n; j++)
{
if (r >= strlen(s)) t[l] = ' ';
else t[l] = s[r];
l++;
r += 3;
}
}
t[len - 1] = 0;
for (i = 0; i < len; i++)
if (' ' != t[i]) printf("%c", t[i]);
free(t);
return 0;
}
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include<string.h>
using namespace std;
int main()
{
ifstream in("data.txt");
string filename;
string line;
int k,n;
char s[1000];
if(in) // 有该文件
{
while (getline (in, line)) // line中不包括每行的换行符
{
cout << line << endl;
n=line.size();
char buf[1000];
strcpy(buf, line.c_str());
k=buf[n-1]-'0';
for(int i=0;i<k;i++)
{
for(int j=i;j<n-1;j+=k) // 输出s[j]
{
cout<<buf[j];
}
}
cout<<endl;
}
}
else // 没有该文件
{
cout <<"no such file" << endl;
system("pause");
}
system("pause");
return 0;
}
int LineCount(int a, int b)
{
int count = 0;
while (a != b)
{
if (a < b)
b = CC[b];
else
a = CC[a];
count++;
}
return count;
}
求两个节点之间的边数 for(int i=0;i<k;i++) for(int j=i;j<|s|;j+=k) // 输出s[j]
(2) 定义 char s[100000], 按刚才倒着放回去就行
二 (1) 定义一个 int parent[100000],读入1 2 时,置 parent[2]=1, 查询直接取parent值
(2) 两结点的共同祖先问题, 自行搜索一下