|
|
back to boardwhy tl#15 Posted by vyu 13 Apr 2009 00:59 #include <iostream> using namespace std; int main() { char x[30005],l='<',r='>',p; int n,i,s=0,k=1; cin>>n; for(i=0; i<n; i++) cin>>x[i]; while(k!=0) { k=0; for(i=0; i<n; i++) if( x[i]==r && x[i+1]==l) { swap(x[i],x[i+1]); s++; k++;} } cout<<s; return 0; } i don't know how to minimize my prog Re: why tl#15 I used very similar code and got AC (though there is a better solution if I recall correctly). What I did is: - Use stdio instead of iostream: it's faster - If you have <<< at left end or >>> at right and, you can ignore those - they will never change again. Thus, you can keep treack of the left and right endings, and only parse those, instead of going from 0 to n every time. AC 0.625 |
|
|