Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isOne(int v){
- if(v%10 == v) return true;
- return false;
- }
- int main()
- {
- int N=10;
- cout<<"enter N : ";
- cin >> N;
- cout<<"enter array : ";
- vector<int>m(N);
- for(int i=0; i<N; ++i)
- {
- cin>>m[i];
- }
- for(int i=1; i<N; ++i)
- {
- int c = m[i];
- if(!isOne(c)) continue;
- int j=0;
- for(; j<i ; ++j)
- {
- if(!isOne(m[j])) continue;
- if(m[j]>c) break;
- }
- int last = m[j];
- m[j] = c;
- for(int k = j+1 ; k<=i; ++k)
- {
- if(isOne(m[k])){
- int t = m[k];
- m[k] = last;
- last = t;
- }
- }
- }
- for(int i=1; i<N; ++i)
- {
- int c = m[i];
- if(isOne(c)) continue;
- int j=0;
- for(; j<i ; ++j)
- {
- if(isOne(m[j])) continue;
- if(m[j]<c) break;
- }
- int last = m[j];
- m[j] = c;
- for(int k = j+1 ; k<=i; ++k)
- {
- if(!isOne(m[k])){
- int t = m[k];
- m[k] = last;
- last = t;
- }
- }
- }
- cout<<endl;
- for(int i=0; i<N; ++i)
- {
- cout<<m[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement