摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1825第一次用C++写,因为是对二维数组排序,所以先在网上了解了一下,这里二维数组用int **来表示了对于sort的用法还要深入了解思路就是先按单价排序,然后将数量一个一个加起来比较 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,m; 6 int **f=new int*[5000]; 7 8 bool cmp(int *a,int *b) 9 {10 if(a[0]== 阅读全文
posted @ 2013-01-22 16:49 tjsuhst 阅读(248) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1824枚举,借用了“回文平方数”里的一些函数 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 int n,s; 6 7 int exam() 8 { 9 int p1=0,p2=(int)strlen(a)-1;10 while(p1<p2)11 {12 if(a[p1]!=a[p2]) {return 0;break;}13 p1++;14 p2--;15 ... 阅读全文
posted @ 2013-01-22 14:55 tjsuhst 阅读(256) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1823涉及到进制转换,要求输出在某进制下的回文数,用字符串处理会方便一些 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 6 void swap() 7 { 8 int l=(int)strlen(a); 9 int p1=0,p2=l-1;10 int t;11 while(p1<p2)12 {13 t=a[p1];14 a[p1++]=a[p2];15 ... 阅读全文
posted @ 2013-01-22 13:36 tjsuhst 阅读(409) 评论(0) 推荐(0)
摘要: 地址:http://hustoj.sinaapp.com/problem.php?id=1820按开始时间排序,然后统计最长挤牛奶时间段和最长间隔段。快排又写错了一次...... 1 #include<stdio.h> 2 3 int a[5000][2],n; 4 5 int ones(int l,int r) 6 { 7 int i=l,j=r,flag=0,key=a[l][0]; 8 int t1,t2; 9 while(i<j)10 {11 if(0==flag)12 {13 if(a[j][... 阅读全文
posted @ 2013-01-22 12:26 tjsuhst 阅读(297) 评论(0) 推荐(0)