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 |
刚刚过,给后来的朋友说说我犯的毛病!其实也是看别人的贴总结出来的 2点 1:最后如果没有符合条件的要cout<<"No duplicates. "<<endl; 2:最后的输出一定要符合条件,我是用的如下格式 printf("%03d-%04d %d\n", tel[k-1]/10000, tel[k-1]%10000, count); 另外贴个我的代码,请大家多多指教,如何能减少时间 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> tel; int line; string s; int num=0; cin>>line; int count=1; for(int i=0;i<line;i++) { cin>>s; for(int j=0;j<s.length();j++) { if(s[j]=='-') continue; num*=10; if(s[j]>47&&s[j]<58) { num+=(s[j]-'0'); continue; } if(s[j]>58&&s[j]<81) { num+=(s[j]-59)/3; continue; } if(s[j]>81) num+=(s[j]-60)/3; } tel.insert(tel.end(),num); num=0; } sort(tel.begin(),tel.end()); bool have=true; int k=0; for(k=1;k<line;k++) { if(tel[k]==tel[k-1]) count++; if(tel[k]!=tel[k-1]&&count>1) { //cout<<tel[k-1]/10000<<"-"<<tel[k-1]%10000<<" "<<count<<endl; printf("%03d-%04d %d\n", tel[k-1]/10000, tel[k-1]%10000, count); count=1; have=false; } } if(tel[k-1]==tel[k-2]&&count>1) { //cout<<tel[k-1]/10000<<"-"<<tel[k-1]%1000<<" "<<count<<endl; printf("%03d-%04d %d\n", tel[k-1]/10000, tel[k-1]%10000, count); have=false; } if(have) cout<<"No duplicates. "<<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