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 "iostream.h" #include "math.h" struct lRGB { int r; int g; int b; lRGB * next; }; void main() { lRGB * first,*cur,*last; lRGB *lsjRGB; lsjRGB = first = cur = new lRGB; cin >> cur->r >> cur->g >> cur->b; while(cur->r!=-1 && cur->g!=-1 && cur->b!=-1) { last = new lRGB; cur->next = last; cur=last; cin >> cur->r >> cur->g >> cur->b; } cur = first + 16; int colorD2; int num = 0; while(cur != last) { int colorD1 = sqrt(pow((cur->r - lsjRGB->r),2) + pow((cur->g - lsjRGB->g),2) + pow((cur->b - lsjRGB->b),2)); for(int i=1; i<16; i++) { colorD2 = sqrt(pow((cur->r - (lsjRGB+i)->r),2) + pow((cur->g - (lsjRGB+i)->g),2) + pow((cur->b - (lsjRGB+i)->b),2)); if(colorD2 < colorD1) colorD1 = colorD2; num = i; } cout << "(" << cur->r << "," << cur->g << "," << cur->b << ")" << "maps to" << "(" << (lsjRGB+num)->r << "," << (lsjRGB+num)->g << "," << (lsjRGB+num)->b << ")" << endl; cur = cur + 1; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator