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 |
谁帮我看一下,与别人的正确程序测的n多组数据都一样,为什么我的总wa???!!!#include <iostream> using namespace std; #include <math.h> int main() { int n,k,t; while(scanf("%d",&n)!=EOF) { for(k=int(sqrt(2.0*n)-1);;k++) { if((1+k)*k/2==n) { if(k%2) printf("TERM %d IS 1/%d\n",k,k); else printf("TERM %d IS %d/1\n",n,k); break; } if((1+k)*k/2<n&&(1+k)*(2+k)/2>n) { t=n-(k+1)*k/2; if(k%2) printf("TERM %d IS %d/%d\n",n,t,k+2-t); else printf("TERM %d IS %d/%d\n",n,k+2-t,t); break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator