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 |
纠结,对string用sort排序,总是超时呢?只好改成数组了#include <iostream> #include <iomanip> #include <math.h> #include <string.h> #include <algorithm> using namespace std; #define ZERO 10E-6 #define PI 3.1415926 int cmp(const void *a,const void *b) { return strcmp((char*)a,(char*)b); } int main() { char str[10101][12]; int n,m,i,len; bool flag; cin>>n; while(n--) { cin>>m; for(i=0;i<m;i++) cin>>str[i]; qsort(str,m,sizeof(str[0]),cmp); for(i=1,flag=true;i<m&&flag;i++) { len=strlen(str[i-1])<=strlen(str[i])?strlen(str[i-1]):strlen(str[i]); if(strncmp(str[i-1],str[i],len)==0) flag=false; } flag?cout<<"YES"<<endl:cout<<"NO"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator