标签:
1 8 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1
1 1 1 1 2 1 1 2 2 2 1 1 2 2 1
。
我心里想不一样吗。。
额,肯定是不一样的。
。须要注意。
#include<iostream> #include<algorithm> using namespace std; struct cfx { int length; int width; int num; }; int cmp(cfx a,cfx b) { if(a.num!=b.num) return a.num<b.num;//升序 else if(a.num==b.num &&a.length!=b.length) return a.length<b.length; else if(a.num==b.num &&a.length==b.length) return a.width<b.width; } int main() { int n,m,i,k; cfx a[1000]; cfx b[1000]; cin>>n; while(n--) { k=0; cin>>m;//m个长方形 for(i=0;i<m;i++) { cin>>a[i].num>>a[i].length>>a[i].width; if(a[i].length<a[i].width) { int t; t=a[i].length; a[i].length=a[i].width; a[i].width=t; } } sort(a,a+m,cmp); for(i=0;i<m;i++) //aabbcc { while(i<m-1 &&a[i].length==a[i+1].length &&a[i].num==a[i+1].num &&a[i].width==a[i+1].width) { i++; } b[k++]=a[i]; } for(i=0;i<k;i++) { cout<<b[i].num<<" "<<b[i].length<<" "<<b[i].width<<endl; } } return 0; }
<dd style="color: rgb(70, 70, 70); font-family: Tahoma, Arial, sans-serif, simsun; font-size: 14px; margin: 0px; padding: 0px;"><pre name="code" class="cpp">//今天又看了一下,能够不用申请b数组。。
<span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; background-color: rgb(253, 253, 253);">#include<iostream></span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">#include<algorithm></span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">using namespace std;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">struct cfx</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int chang;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int kuan;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int num;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">};</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int cmp(cfx a,cfx b)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">if(a.num!=b.num)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">return a.num<b.num;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">else if(a.num==b.num &&a.chang!=b.chang)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">return a.chang<b.chang;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">else if(a.num==b.num &&a.chang==b.chang &&a.kuan!=b.kuan)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">return a.kuan<b.kuan;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int main()</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int T,m,i;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">cfx a[1000];</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">cin>>T;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">while(T--)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">cin>>m;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">for(i=0;i<m;i++)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">cin>>a[i].num>>a[i].chang>>a[i].kuan;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">if(a[i].chang<a[i].kuan)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">int t;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">t=a[i].chang;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">a[i].chang=a[i].kuan;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">a[i].kuan=t;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">sort(a,a+m,cmp);//排序</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">for(i=0;i<m;i++)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">while(i<m-1 && a[i].chang==a[i+1].chang &&a[i].num==a[i+1].num && a[i].kuan==a[i+1].kuan)</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">{</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">i++;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">cout<<a[i].num<<" "<<a[i].chang<<" "<<a[i].kuan<<endl;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">return 0;</span><br style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);" /><span style="font-family: Tahoma, Arial, sans-serif, simsun; font-size: 12.800000190734863px; line-height: 19.5px; text-indent: 20px; background-color: rgb(253, 253, 253);">}</span>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/4721190.html