fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a;
  6. string s;
  7. vector<string>v;
  8.  
  9. cin >> a;
  10.  
  11. for(int i=0;i<a;i++){
  12. int index=i;
  13. cin >> s;
  14. v.push_back(s);
  15. while(index>0 && v[index]<v[index-1]){
  16. swap(v[index],v[index-1]);
  17. index--;
  18. }
  19. cout << index+1 << endl;
  20. }
  21. }
Success #stdin #stdout 0s 4480KB
stdin
5
budi
anir
anisa
andi
tarzan
stdout
1
1
2
1
5