fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t;cin >> t;
  5. while (t--){
  6. int l,r;cin>>l>>r;
  7. int n,m;
  8. int x;
  9. int ans=0;
  10. if (l==0 and r==0){
  11. cout << 0 <<'\n';
  12. continue;
  13. }
  14. else if (l>0 and r>0){
  15. cout << r-l << '\n';
  16. continue;
  17. }
  18. else if (r>0 and l==0){
  19. cout << r-1 << '\n';
  20. continue;
  21. }
  22. else if (l<0 && r<0){
  23. int e=abs(l-r);
  24. cout << e << '\n';
  25. continue;
  26. }
  27. else if (l<0 and r>0)
  28. {
  29. n=abs(l);
  30. m=abs(r);
  31.  
  32. int a[n];
  33. int b[m];
  34. x=l;
  35. for (int i=0;i<n;i++){
  36. a[i]=x;
  37. x++;
  38. }
  39. x=1;
  40. for (int i=0;i<m;i++){
  41. b[i]=x;
  42. x++;
  43. }
  44. if (abs(n)==abs(m)){
  45. cout << 0 << '\n';
  46. continue;
  47. }
  48. else {
  49. int len=abs(n-m);
  50. cout << len -1 << '\n';
  51. }
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. }
  60. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty