Advertisement
hkshakib

Untitled

Feb 2nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define SC scanf
  4. #define PF printf
  5. #define ull unsigned long long
  6. #define ld long double
  7. #define D double
  8. #define F first
  9. #define S second
  10. #define pb push_back
  11. #define pf push_front
  12. #define MP make_pair
  13. #define sort_a(a) sort(a.begin(),a.end());
  14. #define sort_d(a) sort(a.rbegin(),a.rend());
  15. #define READ(f) freopen(f, "r", stdin)
  16. #define WRITE(f) freopen(f, "w", stdout)
  17. #define rev(s) reverse(s.begin(),s.end())
  18. #define it(it,mp) for(auto it=mp.begin() ; it!=mp.end() ; it++)
  19. #define IOS ios_base :: sync_with_stdio(false); cin.tie(NULL);
  20. const int N = 1e5 + 5;
  21. const int inf = 1e9 + 1;
  22. const double eps = 1e-15;
  23. const double EPS = 1e-9;
  24. const double PI = acos(-1.0);
  25. typedef long long int ll;
  26. typedef pair<int,int> PII;
  27. int main()
  28. {
  29. IOS
  30. // READ("test.txt");
  31. //WRITE("");
  32. ll t, n ;
  33. string s;
  34. cin >> t ;
  35. while(t--)
  36. {
  37. cin >> n>> s;
  38. bool flag = true;
  39. int cnt =0 ,pos =0 , pp = 0,ok=0;
  40. for(int i=0 ; i<n ; i++)
  41. {
  42. int tt = s[i]-'0';
  43. if(tt&1 ){
  44. cnt++;
  45. if(ok==0){
  46. pos = i,ok=1;
  47. }
  48. }
  49.  
  50. if(cnt >1 && tt&1)pp = i ;
  51.  
  52. }
  53. if(cnt<=1)
  54. {
  55. cout<<-1<<endl;
  56. }
  57. else
  58. {
  59. if(cnt&1)
  60. {
  61. for(int i=0 ; i<n ; i++)
  62. {
  63. if(i ==pp ){
  64. cout<<s[s.size()-1];
  65. }
  66. else if(i==n-1){
  67. cout<<s[pp];
  68. }
  69. else if(i!=pos)
  70. cout<<s[i];
  71.  
  72. }
  73. cout<<endl;
  74. }
  75. else
  76. {
  77. // cout<<pos<<pp<<endl;
  78. for(int i=0 ; i<n ; i++)
  79. {
  80. if(i ==pp ){
  81. cout<<s[s.size()-1];
  82. }
  83. else if(i==n-1){
  84. cout<<s[pp];
  85. }
  86. else cout<<s[i];
  87. }
  88. cout<<endl;
  89. }
  90.  
  91. }
  92. }
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement