讨论 / [By YangHao] C++ AC
YangHao 2017-09-08 13:29:50
点我顶贴 收藏 删除
scanf("%d",&n);//By YangHao转载请注明出处cryanghao@126.com

while(n>0)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

if(d==1)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

y++;//By YangHao转载请注明出处cryanghao@126.com

n--;//By YangHao转载请注明出处cryanghao@126.com

d=2;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

if(n<=0) break;//By YangHao转载请注明出处cryanghao@126.com

if(d==2)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

while(y!=1&&n>0)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

x++;//By YangHao转载请注明出处cryanghao@126.com

y--;//By YangHao转载请注明出处cryanghao@126.com

n--;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

d=3;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

if(n<=0) break;//By YangHao转载请注明出处cryanghao@126.com

if(d==3)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

x++;//By YangHao转载请注明出处cryanghao@126.com

n--;//By YangHao转载请注明出处cryanghao@126.com

d=4;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

if(n<=0) break;//By YangHao转载请注明出处cryanghao@126.com

if(d==4)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

while(x!=1&&n>0)//By YangHao转载请注明出处cryanghao@126.com

{//By YangHao转载请注明出处cryanghao@126.com

x--;//By YangHao转载请注明出处cryanghao@126.com

y++;//By YangHao转载请注明出处cryanghao@126.com

n--;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

d=1;//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

}//By YangHao转载请注明出处cryanghao@126.com

printf("%d/%d",y,x);//By YangHao转载请注明出处cryanghao@126.com

#1 huangyichen@2017-09-08 13:35:01
回复 删除
#include<cstdio>

int n;

int x=1,y=0;

int d=1;

int main()

{

scanf("%d",&n);

while(n>0)

{

if(d==1)

{

y++;

n--;

d=2;

}

if(n<0)break;

if(d==2)

{

while(y!=1&&n>0)

{

x++,y--;

n--;

}

d=3;

}

if(n<0) break;

if(d==3)

{

x++,n--;d=4;

}

if(n<0)break;

if(d==4)

{

while(x!=1&&n>0)

{

x--,y++;

n--;

}

d=1;

}

}

printf("%d/%d",y,x);

}

查看更多回复
提交回复