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<stdio.h> #define N 102 long int a[N], b[N][N]; long int n, p; void init() { int i; for (i = 1; i < N; i++) { a[i]=i*i*i; } } void sort(long int start,long int end) { long int i,j,temp; for ( i = start; i < end ; i++) { for ( j = start; j < end-i; j++) { if ( b[j][0]>b[j+1][0] || b[j][0]==b[j+1][0]&&b[j][1]>b[j+1][1]) //||b[j][1]==b[j+1][1]&&b[j][2]>b[j+1][2] //||b[j][2]==b[j+1][2]&&b[j][3]>b[j+1][3]) { temp = b[j][0]; b[j][0] = b[j+1][0]; b[j+1][0] = temp; temp = b[j][1]; b[j][1] = b[j+1][1]; b[j+1][1] = temp; temp = b[j][2]; b[j][2] = b[j+1][2]; b[j+1][2] = temp; temp = b[j][3]; b[j][3] = b[j+1][3]; b[j+16][3] = temp; } } } } int main() { long int i, j, k, h, m, t; init(); /*for (i = 2; i < N; i++) printf("a[%d] = %ld\n", i, a[i]);*/ scanf ("%ld", &n); m = n * n * n; for (i = 2; i < N; i++) { if ( m < a[i] ) { p=i; break; } } t=0; for ( i = 2; i < p; i++) { for ( j = i; j < p; j++) { for ( k = j; k < p; k++) { for ( h = k; h < p; h++) { if ( a[i] + a[j] + a[k] == a[h] ) { //printf( "i=%ld j=%ld k=%ld h=%ld\n", i, j, k, h); b[t][0]=h; b[t][1]=i; b[t][2]=j; b[t++][3]=k; break; } } } } } if(t==0) return 0; else { sort( 0, t-1); for ( i = 0; i < t; i++) { printf("Cube = %ld, Triple = (%ld,%ld,%ld)\n", b[i][0], b[i][1], b[i][2], b[i][3]); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator