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 |
过是过了,没有比我更烂的了,1260K 1842MS ,唉,那位大牛能帮我看看那里要改进的吗?求求你们了Source Problem Id:1002 User Id:2004huangyimin Memory:1260K Time:1842MS Language:C++ Result:Accepted Source #include < iostream > #include < cstdlib > #include < iomanip > using namespace std; class keypad { public: void Set ( char c1,char c2,char c3,char k ); char k1 , k2 , k3; char key; }; void keypad::Set( char c1,char c2,char c3,char k ) { k1 = c1; k2 = c2; k3 = c3; key = k; } class rec { public: int num; int fre; }; int comp ( const void* a , const void* b ); int main() { keypad k[8]; k[0].Set( 'A' , 'B' , 'C' , '2' ); k[1].Set( 'D' , 'E' , 'F' , '3' ); k[2].Set( 'G' , 'H' , 'I' , '4' ); k[3].Set( 'J' , 'K' , 'L' , '5' ); k[4].Set( 'M' , 'N' , 'O' , '6' ); k[5].Set( 'P' , 'R' , 'S' , '7' ); k[6].Set( 'T' , 'U' , 'V' , '8' ); k[7].Set( 'W' , 'X' , 'Y' , '9' ); int n , i , j ,t, loc(0) , J ,m; int *c; rec *record ; char phone[7]; char tel[7] , temp ; cin >> n; record = new rec [n]; c = new int [n]; for ( i = 0;i < n; i++ ) { record[i].num = record[i].fre = 0; } for ( J = 0; J < n; J++ ) { for ( j = 0;j < 7; ) { cin >> temp; if ( temp != '-' ) { tel[j] = temp; j++; } } for ( i = 0;i < 7;i++ ) { if ( tel[i] >= 'A' ) { for( j = 0;j < 8; j++ ) { if ( k[j].k1 == tel[i]||k[j].k2 == tel[i]||k[j].k3 == tel[i] ) { phone[i] = k[j].key; break;} } } else { phone[i] = tel[i]; } } t = atoi( phone ); c[J] = t; } qsort( c , n , sizeof(int) , comp); for ( i = 0;i < n; ) { record[i].num = c[i]; for ( j = i;record[i].num == c[j]&& j < n;j++ ){ record[i].fre++; } if ( record[i].fre > 1 ) { t = record[i].num / 10000; m = record[i].num % 10000; cout <<setfill('0')<<setw(3)<<t <<'-'; cout <<setfill('0')<<setw(4)<<m<<' '<<record[i].fre<<endl; loc = 1; } i = j; } if ( loc == 0 ){ cout <<"No duplicates."<<endl;} delete []record; delete []c; return 0; } int comp ( const void* a , const void* b ) { return *((int*)a) - *((int*)b); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator