Advertisement
a53

sirk_V1

a53
Dec 31st, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. ifstream f("ksir.in");
  6. ofstream g("ksir.out");
  7. char s[200000],sir[200000];
  8. unsigned k,x;
  9.  
  10. int main()
  11. {
  12. f.getline(s,200000);
  13. f>>k;
  14. int start,stop;
  15. unsigned lungime=strlen(s),suma,p,q;
  16. while(k)
  17. {
  18. f>>x;
  19. start=0;
  20. p=lungime;
  21. suma=0;
  22. while(suma<x)
  23. {
  24. suma+=p;
  25. --p;
  26. start++;
  27. }
  28. --start;
  29. stop=start+x-suma+p+1;
  30. q=0;
  31. for(int j=start;j<stop;++j)
  32. sir[q++]=s[j];
  33. sir[q]='\0';
  34. sort(sir,sir+q);
  35. g<<sir<<'\n';
  36. --k;
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement