水題,只要找出規(guī)律就好做了。。。。
以斜列來看,列從下往上,分子分母依次遞減和遞增
但奇數(shù)列是從下往上數(shù),而偶數(shù)列則相反
#include <iostream>
#include <string>
using namespace std;

int main()


{
int n;
while (scanf("%d",&n)!=EOF)

{
int k=0,raw=n;
while (n>k)

{
n-=k;
k++;
}
if (k%2==0)
printf("TERM %d IS %d/%d\n",raw,n,k-n+1);
else
printf("TERM %d IS %d/%d\n",raw,k-n+1,n);
}
}

以斜列來看,列從下往上,分子分母依次遞減和遞增
但奇數(shù)列是從下往上數(shù),而偶數(shù)列則相反
#include <iostream>
#include <string>
using namespace std;
int main()

{
int n;
while (scanf("%d",&n)!=EOF)
{
int k=0,raw=n;
while (n>k)
{
n-=k;
k++;
}
if (k%2==0)
printf("TERM %d IS %d/%d\n",raw,n,k-n+1);
else
printf("TERM %d IS %d/%d\n",raw,k-n+1,n);
}
}


