fork download
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cctype>
  4. #include <string>
  5. #include <climits>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. int t;
  12. scanf("%d\n", &t);
  13.  
  14. size_t bytesLength;
  15. char bytesString[3];
  16. int bytes;
  17.  
  18. size_t characterLength;
  19. char character[9];
  20. bool isUnsigned;
  21.  
  22. size_t numberLength;
  23. char numberString[64];
  24. bool isNegative;
  25. unsigned long long int number;
  26. char c;
  27.  
  28. while(t--) {
  29.  
  30. bytesLength = characterLength = numberLength = 0;
  31. while(scanf("%c", &bytesString[bytesLength]) && isdigit(bytesString[bytesLength++]));
  32. while(scanf("%c", &character[characterLength]) && isalpha(character[characterLength++]));
  33. while(scanf("%c", &numberString[numberLength]) && numberString[numberLength++] != '\n');
  34.  
  35. isUnsigned = (character[0] == 'U' ? true : false);
  36. isNegative = (numberString[0] == '-' ? true : false);
  37. number = stoull(numberString + (isNegative ? 1 : 0));
  38. bytes = stoi(bytesString) - 1;
  39.  
  40. unsigned long long maximum;
  41. if(isUnsigned) {
  42. maximum = bytes < 63 ? (1ULL << (bytes + 1)) - 1ULL : ULLONG_MAX;
  43. }
  44. else {
  45. maximum = (1ULL << bytes) - 1ULL;
  46. }
  47.  
  48. unsigned long long minimum = (isUnsigned ? 0ULL : (1ULL << bytes));
  49.  
  50. if(!isUnsigned) {
  51. putchar_unlocked('-');
  52. }
  53.  
  54. printf("%llu %llu ", minimum, maximum);
  55.  
  56. if(isNegative && isUnsigned) {
  57. printf("Ups");
  58. }
  59. else if(!isNegative && number > maximum) {
  60. printf("Ups");
  61. }
  62. else if(isNegative && number > minimum) {
  63. printf("Ups");
  64. }
  65. else {
  66. if(isNegative) {
  67. --number;
  68. }
  69.  
  70. int i = 0;
  71. while(number) {
  72. numberString[i++] = ((number & 1) + '0');
  73. number >>= 1;
  74. }
  75.  
  76. if(isUnsigned) {
  77. ++bytes;
  78. }
  79.  
  80. while(i < bytes) {
  81. numberString[i++] = '0';
  82. }
  83.  
  84. if(isUnsigned) {
  85. --i;
  86. }
  87. else {
  88. numberString[i] = (isNegative ? '1' : '0');
  89. }
  90.  
  91. while(i >= 0) {
  92. putchar_unlocked(numberString[i--]);
  93. }
  94. }
  95.  
  96. putchar_unlocked('\n');
  97. }
  98.  
  99. return 0;
  100. }
Success #stdin #stdout 0s 5280KB
stdin
40
2 SIGNED 0
2 SIGNED 1
2 SIGNED 2
2 SIGNED 3
2 SIGNED -1
2 SIGNED -2
2 SIGNED -3
3 SIGNED 1
3 SIGNED 2
3 SIGNED 3
3 SIGNED 4
3 SIGNED 5
3 SIGNED -1
3 SIGNED -2
3 SIGNED -3
3 SIGNED -4
3 SIGNED -5
1 UNSIGNED 0
1 UNSIGNED 1
1 UNSIGNED 2
2 UNSIGNED 0
2 UNSIGNED 1
2 UNSIGNED 2
2 UNSIGNED 3
2 UNSIGNED 4
3 UNSIGNED 0
3 UNSIGNED 1
3 UNSIGNED 2
3 UNSIGNED 3
3 UNSIGNED 4
3 UNSIGNED 5
64 SIGNED 1
64 SIGNED -1
64 UNSIGNED 1
64 UNSIGNED -1
64 UNSIGNED 9223372036854775807
64 UNSIGNED 9223372036854775808
64 UNSIGNED 9223372036854775809
64 UNSIGNED 18446744073709551614
64 UNSIGNED 18446744073709551615
64 UNSIGNED 18446744073709551616
64 SIGNED 9223372036854775807
64 SIGNED 9223372036854775808
64 SIGNED -9223372036854775807
64 SIGNED -9223372036854775808
64 SIGNED -9223372036854775809
stdout
-2 1 00
-2 1 01
-2 1 Ups
-2 1 Ups
-2 1 10
-2 1 11
-2 1 Ups
-4 3 001
-4 3 010
-4 3 011
-4 3 Ups
-4 3 Ups
-4 3 100
-4 3 101
-4 3 110
-4 3 111
-4 3 Ups
0 1 0
0 1 1
0 1 Ups
0 3 00
0 3 01
0 3 10
0 3 11
0 3 Ups
0 7 000
0 7 001
0 7 010
0 7 011
0 7 100
0 7 101
-9223372036854775808 9223372036854775807 0000000000000000000000000000000000000000000000000000000000000001
-9223372036854775808 9223372036854775807 1000000000000000000000000000000000000000000000000000000000000000
0 18446744073709551615 0000000000000000000000000000000000000000000000000000000000000001
0 18446744073709551615 Ups
0 18446744073709551615 0111111111111111111111111111111111111111111111111111111111111111
0 18446744073709551615 1000000000000000000000000000000000000000000000000000000000000000
0 18446744073709551615 1000000000000000000000000000000000000000000000000000000000000001
0 18446744073709551615 1111111111111111111111111111111111111111111111111111111111111110
0 18446744073709551615 1111111111111111111111111111111111111111111111111111111111111111