id stringlengths 18 123 | pair stringclasses 6
values | Code1 stringlengths 41 1.98k | Code2 stringlengths 41 1.98k | instruction stringclasses 6
values | input stringlengths 56 2k |
|---|---|---|---|---|---|
java-cpp-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM | java-cpp | static String arrangeString ( String str ) {
int char_count [ ] = new int [ MAX_CHAR ] ;
int sum = 0 ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;
else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ... | string arrangeString ( string str ) {
int char_count [ MAX_CHAR ] = {
0 }
;
int sum = 0 ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;
else sum = sum + ( str [ i ] - '0' ) ;
}
string res = ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static String arrangeString ( String str ) {
int char_count [ ] = new int [ MAX_CHAR ] ;
int sum = 0 ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;
else sum = sum + ( str . charAt ( i ) - '... |
java-cpp-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S | java-cpp | static int countStrings ( int n ) {
int a [ ] = new int [ n ] ;
int b [ ] = new int [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
return a [ n - 1 ] + b [ n - 1 ] ;
}
| int countStrings ( int n ) {
int a [ n ] , b [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
return a [ n - 1 ] + b [ n - 1 ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countStrings ( int n ) {
int a [ ] = new int [ n ] ;
int b [ ] = new int [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
return a [ n - 1 ] + b [ n - 1 ] ;
}
</Code> |
java-cpp-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED | java-cpp | static int minSum ( int [ ] arr , int n ) {
int [ ] dp = new int [ n ] ;
if ( n == 1 ) return arr [ 0 ] ;
if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;
if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;
if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] ... | int minSum ( int arr [ ] , int n ) {
int dp [ n ] ;
if ( n == 1 ) return arr [ 0 ] ;
if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;
if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;
if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;
dp [... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int minSum ( int [ ] arr , int n ) {
int [ ] dp = new int [ n ] ;
if ( n == 1 ) return arr [ 0 ] ;
if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;
if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;
if ( n == 4 ) return Math . min ( Math . min ( arr... |
java-cpp-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE | java-cpp | static String printSequence ( String arr [ ] , String input ) {
String output = "" ;
int n = input . length ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( input . charAt ( i ) == ' ▁ ' ) output = output + "0" ;
else {
int position = input . charAt ( i ) - ' A ' ;
output = output + arr [ pos... | string printSequence ( string arr [ ] , string input ) {
string output = "" ;
int n = input . length ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( input [ i ] == ' ' ) output = output + "0" ;
else {
int position = input [ i ] - 'A' ;
output = output + arr [ position ] ;
}
}
return ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static String printSequence ( String arr [ ] , String input ) {
String output = "" ;
int n = input . length ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( input . charAt ( i ) == ' ▁ ' ) output = output + "0" ;
else {
int position = input . charAt ( i ) - ' A ' ;
output = output + ar... |
java-cpp-ROTATE_MATRIX_ELEMENTS | java-cpp | static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {
int row = 0 , col = 0 ;
int prev , curr ;
while ( row < m && col < n ) {
if ( row + 1 == m || col + 1 == n ) break ;
prev = mat [ row + 1 ] [ col ] ;
for ( int i = col ;
i < n ;
i ++ ) {
curr = mat [ row ] [ i ] ;
mat [... | void rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {
int row = 0 , col = 0 ;
int prev , curr ;
while ( row < m && col < n ) {
if ( row + 1 == m || col + 1 == n ) break ;
prev = mat [ row + 1 ] [ col ] ;
for ( int i = col ;
i < n ;
i ++ ) {
curr = mat [ row ] [ i ] ;
mat [ ro... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {
int row = 0 , col = 0 ;
int prev , curr ;
while ( row < m && col < n ) {
if ( row + 1 == m || col + 1 == n ) break ;
prev = mat [ row + 1 ] [ col ] ;
for ( int i = col ;
i < n ;
i ++ ) {
curr = mat [ row ] [ i ] ;
... |
java-cpp-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE | java-cpp | static int maxcoefficientvalue ( int n ) {
int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;
for ( int i = 0 ;
i <= n ;
i ++ ) {
for ( int j = 0 ;
j <= Math . min ( i , n ) ;
j ++ ) {
if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;
else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;... | int maxcoefficientvalue ( int n ) {
int C [ n + 1 ] [ n + 1 ] ;
for ( int i = 0 ;
i <= n ;
i ++ ) {
for ( int j = 0 ;
j <= min ( i , n ) ;
j ++ ) {
if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;
else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;
}
}
int maxvalue = 0 ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maxcoefficientvalue ( int n ) {
int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;
for ( int i = 0 ;
i <= n ;
i ++ ) {
for ( int j = 0 ;
j <= Math . min ( i , n ) ;
j ++ ) {
if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;
else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] ... |
java-cpp-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS | java-cpp | static double gcd ( double a , double b ) {
if ( a < b ) return gcd ( b , a ) ;
if ( Math . abs ( b ) < 0.001 ) return a ;
else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;
}
| double gcd ( double a , double b ) {
if ( a < b ) return gcd ( b , a ) ;
if ( fabs ( b ) < 0.001 ) return a ;
else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static double gcd ( double a , double b ) {
if ( a < b ) return gcd ( b , a ) ;
if ( Math . abs ( b ) < 0.001 ) return a ;
else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;
}
</Code> |
java-cpp-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING | java-cpp | static void sortByPattern ( char [ ] str , char [ ] pat ) {
int count [ ] = new int [ MAX_CHAR ] ;
for ( int i = 0 ;
i < str . length ;
i ++ ) {
count [ str [ i ] - ' a ' ] ++ ;
}
int index = 0 ;
for ( int i = 0 ;
i < pat . length ;
i ++ ) {
for ( int j = 0 ;
j < count [ pat [ i ] - ' a ' ... | void sortByPattern ( string & str , string pat ) {
int count [ MAX_CHAR ] = {
0 }
;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) count [ str [ i ] - 'a' ] ++ ;
int index = 0 ;
for ( int i = 0 ;
i < pat . length ( ) ;
i ++ ) for ( int j = 0 ;
j < count [ pat [ i ] - 'a' ] ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void sortByPattern ( char [ ] str , char [ ] pat ) {
int count [ ] = new int [ MAX_CHAR ] ;
for ( int i = 0 ;
i < str . length ;
i ++ ) {
count [ str [ i ] - ' a ' ] ++ ;
}
int index = 0 ;
for ( int i = 0 ;
i < pat . length ;
i ++ ) {
for ( int j = 0 ;
j < count [ pat [ i ] -... |
java-cpp-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE | java-cpp | public static void rearrange ( int arr [ ] , int n ) {
int max_idx = n - 1 , min_idx = 0 ;
int max_elem = arr [ n - 1 ] + 1 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( i % 2 == 0 ) {
arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;
max_idx -- ;
}
else {
arr [ i ] += ( arr [... | void rearrange ( int arr [ ] , int n ) {
int max_idx = n - 1 , min_idx = 0 ;
int max_elem = arr [ n - 1 ] + 1 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( i % 2 == 0 ) {
arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;
max_idx -- ;
}
else {
arr [ i ] += ( arr [ min_idx ] % m... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static void rearrange ( int arr [ ] , int n ) {
int max_idx = n - 1 , min_idx = 0 ;
int max_elem = arr [ n - 1 ] + 1 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( i % 2 == 0 ) {
arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;
max_idx -- ;
}
else {
arr [ i ] += ... |
java-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1 | java-cpp | private static int minJumps ( int [ ] arr , int n ) {
int jumps [ ] = new int [ n ] ;
int i , j ;
if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;
jumps [ 0 ] = 0 ;
for ( i = 1 ;
i < n ;
i ++ ) {
jumps [ i ] = Integer . MAX_VALUE ;
for ( j = 0 ;
j < i ;
j ++ ) {
if ( i <=... | int minJumps ( int arr [ ] , int n ) {
int * jumps = new int [ n ] ;
int i , j ;
if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;
jumps [ 0 ] = 0 ;
for ( i = 1 ;
i < n ;
i ++ ) {
jumps [ i ] = INT_MAX ;
for ( j = 0 ;
j < i ;
j ++ ) {
if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
private static int minJumps ( int [ ] arr , int n ) {
int jumps [ ] = new int [ n ] ;
int i , j ;
if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;
jumps [ 0 ] = 0 ;
for ( i = 1 ;
i < n ;
i ++ ) {
jumps [ i ] = Integer . MAX_VALUE ;
for ( j = 0 ;
j < i ;
j ++ ) {
if... |
java-cpp-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME | java-cpp | static float find_prob ( int N , float P ) {
double dp [ ] = new double [ N + 1 ] ;
dp [ 0 ] = 1 ;
dp [ 1 ] = 0 ;
dp [ 2 ] = P ;
dp [ 3 ] = 1 - P ;
for ( int i = 4 ;
i <= N ;
++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;
return ( ( float ) ( dp [ N ] ) ) ;
}
| float find_prob ( int N , float P ) {
double dp [ N + 1 ] ;
dp [ 0 ] = 1 ;
dp [ 1 ] = 0 ;
dp [ 2 ] = P ;
dp [ 3 ] = 1 - P ;
for ( int i = 4 ;
i <= N ;
++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;
return dp [ N ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static float find_prob ( int N , float P ) {
double dp [ ] = new double [ N + 1 ] ;
dp [ 0 ] = 1 ;
dp [ 1 ] = 0 ;
dp [ 2 ] = P ;
dp [ 3 ] = 1 - P ;
for ( int i = 4 ;
i <= N ;
++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;
return ( ( float ) ( dp [ N ] ) ) ;
}
</Code> |
java-cpp-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE | java-cpp | static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {
int m = str1 . length ( ) , n = str2 . length ( ) ;
Vector < Integer > [ ] position = new Vector [ M ] ;
for ( int i = 0 ;
i < M ;
i ++ ) position [ i ] = new Vector < > ( ) ;
for ( int i = 1 ;
i <= n ;
i ++ ) position [ str2 . charAt ( i -... | int waysToIncreaseLCSBy1 ( string str1 , string str2 ) {
int m = str1 . length ( ) , n = str2 . length ( ) ;
vector < int > position [ M ] ;
for ( int i = 1 ;
i <= n ;
i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;
int lcsl [ m + 2 ] [ n + 2 ] ;
int lcsr [ m + 2 ] [ n + 2 ] ;
for ( int... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {
int m = str1 . length ( ) , n = str2 . length ( ) ;
Vector < Integer > [ ] position = new Vector [ M ] ;
for ( int i = 0 ;
i < M ;
i ++ ) position [ i ] = new Vector < > ( ) ;
for ( int i = 1 ;
i <= n ;
i ++ ) position [ str2 . charA... |
java-cpp-LONGEST_INCREASING_SUBSEQUENCE_1 | java-cpp | static int lis ( int arr [ ] , int n ) {
int lis [ ] = new int [ n ] ;
int i , j , max = 0 ;
for ( i = 0 ;
i < n ;
i ++ ) lis [ i ] = 1 ;
for ( i = 1 ;
i < n ;
i ++ ) for ( j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
for ( i = 0 ;
... | int lis ( int arr [ ] , int n ) {
int lis [ n ] ;
lis [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
lis [ i ] = 1 ;
for ( int j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
}
return * max_element ( lis , lis + n ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int lis ( int arr [ ] , int n ) {
int lis [ ] = new int [ n ] ;
int i , j , max = 0 ;
for ( i = 0 ;
i < n ;
i ++ ) lis [ i ] = 1 ;
for ( i = 1 ;
i < n ;
i ++ ) for ( j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
for ( i =... |
java-cpp-STERN_BROCOT_SEQUENCE | java-cpp | static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {
for ( int i = 1 ;
BrocotSequence . size ( ) < n ;
i ++ ) {
int considered_element = BrocotSequence . get ( i ) ;
int precedent = BrocotSequence . get ( i - 1 ) ;
BrocotSequence . add ( considered_element + precedent ) ;
... | void SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {
for ( int i = 1 ;
BrocotSequence . size ( ) < n ;
i ++ ) {
int considered_element = BrocotSequence [ i ] ;
int precedent = BrocotSequence [ i - 1 ] ;
BrocotSequence . push_back ( considered_element + precedent ) ;
BrocotSequence ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {
for ( int i = 1 ;
BrocotSequence . size ( ) < n ;
i ++ ) {
int considered_element = BrocotSequence . get ( i ) ;
int precedent = BrocotSequence . get ( i - 1 ) ;
BrocotSequence . add ( considered_element + precedent )... |
java-cpp-PRUFER_CODE_TREE_CREATION | java-cpp | static void printTreeEdges ( int prufer [ ] , int m ) {
int vertices = m + 2 ;
int vertex_set [ ] = new int [ vertices ] ;
for ( int i = 0 ;
i < vertices ;
i ++ ) vertex_set [ i ] = 0 ;
for ( int i = 0 ;
i < vertices - 2 ;
i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;
System . out . print ( "\nThe edg... | void printTreeEdges ( int prufer [ ] , int m ) {
int vertices = m + 2 ;
int vertex_set [ vertices ] ;
for ( int i = 0 ;
i < vertices ;
i ++ ) vertex_set [ i ] = 0 ;
for ( int i = 0 ;
i < vertices - 2 ;
i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;
cout << "\nThe edge set E(G) is :\n" ;
int j = 0 ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void printTreeEdges ( int prufer [ ] , int m ) {
int vertices = m + 2 ;
int vertex_set [ ] = new int [ vertices ] ;
for ( int i = 0 ;
i < vertices ;
i ++ ) vertex_set [ i ] = 0 ;
for ( int i = 0 ;
i < vertices - 2 ;
i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;
System . out . print ( "\n... |
java-cpp-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1 | java-cpp | static int countDecodingDP ( char digits [ ] , int n ) {
int count [ ] = new int [ n + 1 ] ;
count [ 0 ] = 1 ;
count [ 1 ] = 1 ;
if ( digits [ 0 ] == ' 0 ' ) return 0 ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
count [ i ] = 0 ;
if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;
if ( di... | int countDecodingDP ( char * digits , int n ) {
int count [ n + 1 ] ;
count [ 0 ] = 1 ;
count [ 1 ] = 1 ;
if ( digits [ 0 ] == '0' ) return 0 ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
count [ i ] = 0 ;
if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;
if ( digits [ i - 2 ] == '1' || ( ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countDecodingDP ( char digits [ ] , int n ) {
int count [ ] = new int [ n + 1 ] ;
count [ 0 ] = 1 ;
count [ 1 ] = 1 ;
if ( digits [ 0 ] == ' 0 ' ) return 0 ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
count [ i ] = 0 ;
if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;
... |
java-cpp-COUNT_STRINGS_WITH_CONSECUTIVE_1S | java-cpp | static int countStrings ( int n ) {
int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;
}
| int countStrings ( int n ) {
int a [ n ] , b [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countStrings ( int n ) {
int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;
a [ 0 ] = b [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;
b [ i ] = a [ i - 1 ] ;
}
from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;
}
</Code> |
java-cpp-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C | java-cpp | static int maximumSegments ( int n , int a , int b , int c ) {
int dp [ ] = new int [ n + 10 ] ;
Arrays . fill ( dp , - 1 ) ;
dp [ 0 ] = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( dp [ i ] != - 1 ) {
if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;
if ( i + b <=... | int maximumSegments ( int n , int a , int b , int c ) {
int dp [ n + 1 ] ;
memset ( dp , - 1 , sizeof ( dp ) ) ;
dp [ 0 ] = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( dp [ i ] != - 1 ) {
if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;
if ( i + b <= n ) dp [ i + b ] = ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maximumSegments ( int n , int a , int b , int c ) {
int dp [ ] = new int [ n + 10 ] ;
Arrays . fill ( dp , - 1 ) ;
dp [ 0 ] = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( dp [ i ] != - 1 ) {
if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;
if ( i... |
java-cpp-PRINT_BRACKET_NUMBER | java-cpp | static void printBracketNumber ( String exp , int n ) {
int left_bnum = 1 ;
Stack < Integer > right_bnum = new Stack < Integer > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( exp . charAt ( i ) == ' ( ' ) {
System . out . print ( left_bnum + " " ) ;
right_bnum . push ( left_bnum ) ;
left... | void printBracketNumber ( string exp , int n ) {
int left_bnum = 1 ;
stack < int > right_bnum ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( exp [ i ] == '(' ) {
cout << left_bnum << " " ;
right_bnum . push ( left_bnum ) ;
left_bnum ++ ;
}
else if ( exp [ i ] == ')' ) {
cout << ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void printBracketNumber ( String exp , int n ) {
int left_bnum = 1 ;
Stack < Integer > right_bnum = new Stack < Integer > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( exp . charAt ( i ) == ' ( ' ) {
System . out . print ( left_bnum + " " ) ;
right_bnum . push ( left_bnum ) ;
... |
java-cpp-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD | java-cpp | static int countWords ( String str , int len ) {
int count = 1 ;
if ( len == 1 ) return count ;
if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;
else count *= 2 ;
for ( int j = 1 ;
j < len - 1 ;
j ++ ) {
if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charA... | int countWords ( char str [ ] , int len ) {
int count = 1 ;
if ( len == 1 ) return count ;
if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;
else count *= 2 ;
for ( int j = 1 ;
j < len - 1 ;
j ++ ) {
if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;
else if ( str [ j ] == str [... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countWords ( String str , int len ) {
int count = 1 ;
if ( len == 1 ) return count ;
if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;
else count *= 2 ;
for ( int j = 1 ;
j < len - 1 ;
j ++ ) {
if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str ... |
java-cpp-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY | java-cpp | static int largest ( ) {
int i ;
int max = arr [ 0 ] ;
for ( i = 1 ;
i < arr . length ;
i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;
return max ;
}
| int largest ( int arr [ ] , int n ) {
int i ;
int max = arr [ 0 ] ;
for ( i = 1 ;
i < n ;
i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;
return max ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int largest ( ) {
int i ;
int max = arr [ 0 ] ;
for ( i = 1 ;
i < arr . length ;
i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;
return max ;
}
</Code> |
java-cpp-FIND_MINIMUM_DIFFERENCE_PAIR | java-cpp | static int findMinDiff ( int [ ] arr , int n ) {
int diff = Integer . MAX_VALUE ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) for ( int j = i + 1 ;
j < n ;
j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;
return diff ;
}
| int findMinDiff ( int arr [ ] , int n ) {
int diff = INT_MAX ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) for ( int j = i + 1 ;
j < n ;
j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;
return diff ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int findMinDiff ( int [ ] arr , int n ) {
int diff = Integer . MAX_VALUE ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) for ( int j = i + 1 ;
j < n ;
j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;
return diff ;
}
</Code> |
java-cpp-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY | java-cpp | static int maxSum ( int arr [ ] , int n ) {
int res = Integer . MIN_VALUE ;
for ( int i = 0 ;
i < n ;
i ++ ) {
int curr_sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
int index = ( i + j ) % n ;
curr_sum += j * arr [ index ] ;
}
res = Math . max ( res , curr_sum ) ;
}
retur... | int maxSum ( int arr [ ] , int n ) {
int res = INT_MIN ;
for ( int i = 0 ;
i < n ;
i ++ ) {
int curr_sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
int index = ( i + j ) % n ;
curr_sum += j * arr [ index ] ;
}
res = max ( res , curr_sum ) ;
}
return res ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maxSum ( int arr [ ] , int n ) {
int res = Integer . MIN_VALUE ;
for ( int i = 0 ;
i < n ;
i ++ ) {
int curr_sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
int index = ( i + j ) % n ;
curr_sum += j * arr [ index ] ;
}
res = Math . max ( res , curr_sum ) ;
}
... |
java-cpp-PROGRAM_CALCULATE_VOLUME_ELLIPSOID | java-cpp | public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {
float pi = ( float ) 3.14 ;
return ( float ) 1.33 * pi * r1 * r2 * r3 ;
}
| float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {
float pi = 3.14 ;
return 1.33 * pi * r1 * r2 * r3 ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {
float pi = ( float ) 3.14 ;
return ( float ) 1.33 * pi * r1 * r2 * r3 ;
}
</Code> |
java-cpp-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS | java-cpp | static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {
int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;
for ( int i = 0 ;
i <= m ;
i ++ ) {
for ( int j = 0 ;
j <= n ;
j ++ ) {
for ( int k = 0 ;
k <= o ;
k ++ ) {
if ( i == 0 || j == 0 || k ... | int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {
int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;
for ( int i = 0 ;
i <= m ;
i ++ ) {
for ( int j = 0 ;
j <= n ;
j ++ ) {
for ( int k = 0 ;
k <= o ;
k ++ ) {
if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {
int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;
for ( int i = 0 ;
i <= m ;
i ++ ) {
for ( int j = 0 ;
j <= n ;
j ++ ) {
for ( int k = 0 ;
k <= o ;
k ++ ) {
if ( i == 0 || j == ... |
java-cpp-FIND_NUMBER_ENDLESS_POINTS | java-cpp | static int countEndless ( boolean input [ ] [ ] , int n ) {
boolean row [ ] [ ] = new boolean [ n ] [ n ] ;
boolean col [ ] [ ] = new boolean [ n ] [ n ] ;
for ( int j = 0 ;
j < n ;
j ++ ) {
boolean isEndless = true ;
for ( int i = n - 1 ;
i >= 0 ;
i -- ) {
if ( input [ i ] [ j ] == fals... | int countEndless ( bool input [ ] [ MAX ] , int n ) {
bool row [ n ] [ n ] , col [ n ] [ n ] ;
for ( int j = 0 ;
j < n ;
j ++ ) {
bool isEndless = 1 ;
for ( int i = n - 1 ;
i >= 0 ;
i -- ) {
if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;
col [ i ] [ j ] = isEndless ;
}
}
for (... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countEndless ( boolean input [ ] [ ] , int n ) {
boolean row [ ] [ ] = new boolean [ n ] [ n ] ;
boolean col [ ] [ ] = new boolean [ n ] [ n ] ;
for ( int j = 0 ;
j < n ;
j ++ ) {
boolean isEndless = true ;
for ( int i = n - 1 ;
i >= 0 ;
i -- ) {
if ( input [ i ] [ j ] ... |
java-cpp-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT | java-cpp | static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {
int allocation [ ] = new int [ n ] , j = 0 ;
Arrays . fill ( allocation , - 1 ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
while ( j < m ) {
if ( blockSize [ j ] >= processSize [ i ] ) {
allocation [ i ] = j ;
... | void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {
int allocation [ n ] , j = 0 ;
memset ( allocation , - 1 , sizeof ( allocation ) ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
while ( j < m ) {
if ( blockSize [ j ] >= processSize [ i ] ) {
allocation [ i ] = j ;
bl... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {
int allocation [ ] = new int [ n ] , j = 0 ;
Arrays . fill ( allocation , - 1 ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
while ( j < m ) {
if ( blockSize [ j ] >= processSize [ i ] ) {
allocation [ i ] = j ;... |
java-cpp-LONGEST_GEOMETRIC_PROGRESSION | java-cpp | static int lenOfLongestGP ( int set [ ] , int n ) {
if ( n < 2 ) {
return n ;
}
if ( n == 2 ) {
return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;
}
Arrays . sort ( set ) ;
int L [ ] [ ] = new int [ n ] [ n ] ;
int llgp = 1 ;
for ( int i = 0 ;
i < n ;
++ i ) {
if ( set [ n - 1 ] % set [ i ]... | int lenOfLongestGP ( int set [ ] , int n ) {
if ( n < 2 ) return n ;
if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;
sort ( set , set + n ) ;
int L [ n ] [ n ] ;
int llgp = 1 ;
for ( int i = 0 ;
i < n ;
++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;
else L [ i ] [ n - 1 ] =... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int lenOfLongestGP ( int set [ ] , int n ) {
if ( n < 2 ) {
return n ;
}
if ( n == 2 ) {
return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;
}
Arrays . sort ( set ) ;
int L [ ] [ ] = new int [ n ] [ n ] ;
int llgp = 1 ;
for ( int i = 0 ;
i < n ;
++ i ) {
if ( set [ n - 1 ] % se... |
java-cpp-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN | java-cpp | public static int checkValidity ( int a , int b , int c ) {
if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;
else return 1 ;
}
| bool checkValidity ( int a , int b , int c ) {
if ( a + b <= c || a + c <= b || b + c <= a ) return false ;
else return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static int checkValidity ( int a , int b , int c ) {
if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;
else return 1 ;
}
</Code> |
java-cpp-DIAGONALLY_DOMINANT_MATRIX | java-cpp | static boolean isDDM ( int m [ ] [ ] , int n ) {
for ( int i = 0 ;
i < n ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;
sum -= Math . abs ( m [ i ] [ i ] ) ;
if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;
}
return true ;
}
| bool isDDM ( int m [ N ] [ N ] , int n ) {
for ( int i = 0 ;
i < n ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += abs ( m [ i ] [ j ] ) ;
sum -= abs ( m [ i ] [ i ] ) ;
if ( abs ( m [ i ] [ i ] ) < sum ) return false ;
}
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isDDM ( int m [ ] [ ] , int n ) {
for ( int i = 0 ;
i < n ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;
sum -= Math . abs ( m [ i ] [ i ] ) ;
if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;
}
return true ;... |
java-cpp-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX | java-cpp | static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {
int i , j ;
for ( i = 0 ;
i < N ;
i ++ ) for ( j = 0 ;
j < N ;
j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;
}
| void transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {
int i , j ;
for ( i = 0 ;
i < N ;
i ++ ) for ( j = 0 ;
j < N ;
j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {
int i , j ;
for ( i = 0 ;
i < N ;
i ++ ) for ( j = 0 ;
j < N ;
j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;
}
</Code> |
java-cpp-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE | java-cpp | static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {
Set < Integer > mp = new HashSet < Integer > ( ) ;
int result = 0 ;
int curr_sum = 0 , curr_begin = 0 ;
for ( int i = 0 ;
i < n ;
++ i ) {
while ( mp . contains ( A [ i ] ) ) {
mp . remove ( A [ curr_begin ] ) ;
curr_sum -= B [ curr... | int returnMaxSum ( int A [ ] , int B [ ] , int n ) {
unordered_set < int > mp ;
int result = 0 ;
int curr_sum = 0 , curr_begin = 0 ;
for ( int i = 0 ;
i < n ;
++ i ) {
while ( mp . find ( A [ i ] ) != mp . end ( ) ) {
mp . erase ( A [ curr_begin ] ) ;
curr_sum -= B [ curr_begin ] ;
cur... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {
Set < Integer > mp = new HashSet < Integer > ( ) ;
int result = 0 ;
int curr_sum = 0 , curr_begin = 0 ;
for ( int i = 0 ;
i < n ;
++ i ) {
while ( mp . contains ( A [ i ] ) ) {
mp . remove ( A [ curr_begin ] ) ;
curr_sum -= B... |
java-cpp-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT | java-cpp | static int sumEqualProduct ( int a [ ] , int n ) {
int zero = 0 , two = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( a [ i ] == 0 ) {
zero ++ ;
}
if ( a [ i ] == 2 ) {
two ++ ;
}
}
int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;
return cnt ;
}
| int sumEqualProduct ( int a [ ] , int n ) {
int zero = 0 , two = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( a [ i ] == 0 ) {
zero ++ ;
}
if ( a [ i ] == 2 ) {
two ++ ;
}
}
int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;
return cnt ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int sumEqualProduct ( int a [ ] , int n ) {
int zero = 0 , two = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( a [ i ] == 0 ) {
zero ++ ;
}
if ( a [ i ] == 2 ) {
two ++ ;
}
}
int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;
return cnt ;
}
</Code> |
java-cpp-MULTISTAGE_GRAPH_SHORTEST_PATH | java-cpp | public static int shortestDist ( int [ ] [ ] graph ) {
int [ ] dist = new int [ N ] ;
dist [ N - 1 ] = 0 ;
for ( int i = N - 2 ;
i >= 0 ;
i -- ) {
dist [ i ] = INF ;
for ( int j = i ;
j < N ;
j ++ ) {
if ( graph [ i ] [ j ] == INF ) {
continue ;
}
dist [ i ] = Math . ... | INT_MAX int shortestDist ( int graph [ N ] [ N ] ) {
int dist [ N ] ;
dist [ N - 1 ] = 0 ;
for ( int i = N - 2 ;
i >= 0 ;
i -- ) {
dist [ i ] = INF ;
for ( int j = i ;
j < N ;
j ++ ) {
if ( graph [ i ] [ j ] == INF ) continue ;
dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + di... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static int shortestDist ( int [ ] [ ] graph ) {
int [ ] dist = new int [ N ] ;
dist [ N - 1 ] = 0 ;
for ( int i = N - 2 ;
i >= 0 ;
i -- ) {
dist [ i ] = INF ;
for ( int j = i ;
j < N ;
j ++ ) {
if ( graph [ i ] [ j ] == INF ) {
continue ;
}
dist [ i ] = ... |
java-cpp-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1 | java-cpp | static long calculateSum ( int n ) {
long sum = 0 ;
sum = 1 << n ;
return ( sum - 1 ) ;
}
| long long int calculateSum ( int n ) {
long long int sum = 0 ;
sum = 1 << n ;
return ( sum - 1 ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static long calculateSum ( int n ) {
long sum = 0 ;
sum = 1 << n ;
return ( sum - 1 ) ;
}
</Code> |
java-cpp-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1 | java-cpp | static boolean isPrime ( int n ) {
if ( n <= 1 ) return false ;
if ( n <= 3 ) return true ;
if ( n % 2 == 0 || n % 3 == 0 ) return false ;
for ( int i = 5 ;
i * i <= n ;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;
return true ;
}
| bool isPrime ( int n ) {
if ( n <= 1 ) return false ;
if ( n <= 3 ) return true ;
if ( n % 2 == 0 || n % 3 == 0 ) return false ;
for ( int i = 5 ;
i * i <= n ;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isPrime ( int n ) {
if ( n <= 1 ) return false ;
if ( n <= 3 ) return true ;
if ( n % 2 == 0 || n % 3 == 0 ) return false ;
for ( int i = 5 ;
i * i <= n ;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;
return true ;
}
</Code> |
java-cpp-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1 | java-cpp | static void fib ( int n ) {
int a = 0 , b = 1 ;
if ( n >= 0 ) System . out . print ( a + " " ) ;
if ( n >= 1 ) System . out . print ( b + " " ) ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
System . out . print ( a + b + " " ) ;
b = a + b ;
a = b - a ;
}
}
| void fib ( int n ) {
int a = 0 , b = 1 ;
if ( n >= 0 ) cout << a << " " ;
if ( n >= 1 ) cout << b << " " ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
cout << a + b << " " ;
b = a + b ;
a = b - a ;
}
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void fib ( int n ) {
int a = 0 , b = 1 ;
if ( n >= 0 ) System . out . print ( a + " " ) ;
if ( n >= 1 ) System . out . print ( b + " " ) ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
System . out . print ( a + b + " " ) ;
b = a + b ;
a = b - a ;
}
}
</Code> |
java-cpp-K_TH_DIGIT_RAISED_POWER_B | java-cpp | public static int kthdigit ( int a , int b , int k ) {
int p = ( int ) Math . pow ( a , b ) ;
int count = 0 ;
while ( p > 0 && count < k ) {
int rem = p % 10 ;
count ++ ;
if ( count == k ) return rem ;
p = p / 10 ;
}
return 0 ;
}
| int kthdigit ( int a , int b , int k ) {
int p = pow ( a , b ) ;
int count = 0 ;
while ( p > 0 && count < k ) {
int rem = p % 10 ;
count ++ ;
if ( count == k ) return rem ;
p = p / 10 ;
}
return 0 ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static int kthdigit ( int a , int b , int k ) {
int p = ( int ) Math . pow ( a , b ) ;
int count = 0 ;
while ( p > 0 && count < k ) {
int rem = p % 10 ;
count ++ ;
if ( count == k ) return rem ;
p = p / 10 ;
}
return 0 ;
}
</Code> |
java-cpp-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1 | java-cpp | public static boolean isEven ( int n ) {
if ( ( n & 1 ) == 0 ) return true ;
else return false ;
}
| bool isEven ( int n ) {
return ( ! ( n & 1 ) ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static boolean isEven ( int n ) {
if ( ( n & 1 ) == 0 ) return true ;
else return false ;
}
</Code> |
java-cpp-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN | java-cpp | static void printPath ( String str ) {
int i = 0 ;
int curX = 0 , curY = 0 ;
while ( i < str . length ( ) ) {
int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;
int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;
while ( curX > nextX ) {
System . out . println ( "Move Up" ) ;
curX -- ;
... | void printPath ( string str ) {
int i = 0 ;
int curX = 0 , curY = 0 ;
while ( i < str . length ( ) ) {
int nextX = ( str [ i ] - 'A' ) / 5 ;
int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;
while ( curX > nextX ) {
cout << "Move Up" << endl ;
curX -- ;
}
while ( curY > nextY ) {
cou... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void printPath ( String str ) {
int i = 0 ;
int curX = 0 , curY = 0 ;
while ( i < str . length ( ) ) {
int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;
int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;
while ( curX > nextX ) {
System . out . println ( "Move Up" ) ;
curX --... |
java-cpp-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES | java-cpp | public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {
int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;
return ( dis - r1 >= R && dis + r1 <= r ) ;
}
| bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {
int dis = sqrt ( x1 * x1 + y1 * y1 ) ;
return ( dis - r1 >= R && dis + r1 <= r ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {
int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;
return ( dis - r1 >= R && dis + r1 <= r ) ;
}
</Code> |
java-cpp-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP | java-cpp | static boolean isMinHeap ( int [ ] level ) {
int n = level . length - 1 ;
for ( int i = ( n / 2 - 1 ) ;
i >= 0 ;
i -- ) {
if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;
if ( 2 * i + 2 < n ) {
if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;
}
}
return true ;
}
| bool isMinHeap ( int level [ ] , int n ) {
for ( int i = ( n / 2 - 1 ) ;
i >= 0 ;
i -- ) {
if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;
if ( 2 * i + 2 < n ) {
if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;
}
}
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isMinHeap ( int [ ] level ) {
int n = level . length - 1 ;
for ( int i = ( n / 2 - 1 ) ;
i >= 0 ;
i -- ) {
if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;
if ( 2 * i + 2 < n ) {
if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;
}
}
return true ;
}
</Cod... |
java-cpp-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS | java-cpp | static void thirdLargest ( int arr [ ] , int arr_size ) {
if ( arr_size < 3 ) {
System . out . printf ( " Invalid Input " ) ;
return ;
}
int first = arr [ 0 ] ;
for ( int i = 1 ;
i < arr_size ;
i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;
int second = Integer . MIN_VALUE ;
for ( int i = 0... | void thirdLargest ( int arr [ ] , int arr_size ) {
if ( arr_size < 3 ) {
printf ( " Invalid Input " ) ;
return ;
}
int first = arr [ 0 ] ;
for ( int i = 1 ;
i < arr_size ;
i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;
int second = INT_MIN ;
for ( int i = 0 ;
i < arr_size ;
i ++ ) if ( ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void thirdLargest ( int arr [ ] , int arr_size ) {
if ( arr_size < 3 ) {
System . out . printf ( " Invalid Input " ) ;
return ;
}
int first = arr [ 0 ] ;
for ( int i = 1 ;
i < arr_size ;
i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;
int second = Integer . MIN_VALUE ;
for ( in... |
java-cpp-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE | java-cpp | static int maxHamming ( int arr [ ] , int n ) {
int brr [ ] = new int [ 2 * n + 1 ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ i ] = arr [ i ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ n + i ] = arr [ i ] ;
int maxHam = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
int currHam = 0 ;
for ( int j = i ... | int maxHamming ( int arr [ ] , int n ) {
int brr [ 2 * n + 1 ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ i ] = arr [ i ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ n + i ] = arr [ i ] ;
int maxHam = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
int currHam = 0 ;
for ( int j = i , k = 0 ;
j < ( i... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maxHamming ( int arr [ ] , int n ) {
int brr [ ] = new int [ 2 * n + 1 ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ i ] = arr [ i ] ;
for ( int i = 0 ;
i < n ;
i ++ ) brr [ n + i ] = arr [ i ] ;
int maxHam = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
int currHam = 0 ;
for ( int... |
java-cpp-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER | java-cpp | static int findSum ( int N , int K ) {
int ans = 0 ;
for ( int i = 1 ;
i <= N ;
i ++ ) ans += ( i % K ) ;
return ans ;
}
| int findSum ( int N , int K ) {
int ans = 0 ;
for ( int i = 1 ;
i <= N ;
i ++ ) ans += ( i % K ) ;
return ans ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int findSum ( int N , int K ) {
int ans = 0 ;
for ( int i = 1 ;
i <= N ;
i ++ ) ans += ( i % K ) ;
return ans ;
}
</Code> |
java-cpp-SUM_SERIES_23_45_67_89_UPTO_N_TERMS | java-cpp | static double seriesSum ( int n ) {
int i = 1 ;
double res = 0.0 ;
boolean sign = true ;
while ( n > 0 ) {
n -- ;
if ( sign ) {
sign = ! sign ;
res = res + ( double ) ++ i / ++ i ;
}
else {
sign = ! sign ;
res = res - ( double ) ++ i / ++ i ;
}
}
return res ;
}
| double seriesSum ( int n ) {
int i = 1 ;
double res = 0.0 ;
bool sign = true ;
while ( n > 0 ) {
n -- ;
if ( sign ) {
sign = ! sign ;
res = res + ( double ) ++ i / ++ i ;
}
else {
sign = ! sign ;
res = res - ( double ) ++ i / ++ i ;
}
}
return res ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static double seriesSum ( int n ) {
int i = 1 ;
double res = 0.0 ;
boolean sign = true ;
while ( n > 0 ) {
n -- ;
if ( sign ) {
sign = ! sign ;
res = res + ( double ) ++ i / ++ i ;
}
else {
sign = ! sign ;
res = res - ( double ) ++ i / ++ i ;
}
}
return res... |
java-cpp-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N | java-cpp | static int countSetBits ( int n ) {
int i = 0 ;
int ans = 0 ;
while ( ( 1 << i ) <= n ) {
boolean k = false ;
int change = 1 << i ;
for ( int j = 0 ;
j <= n ;
j ++ ) {
if ( k == true ) ans += 1 ;
else ans += 0 ;
if ( change == 1 ) {
k = ! k ;
change = 1 << i ;... | int countSetBits ( int n ) {
int i = 0 ;
int ans = 0 ;
while ( ( 1 << i ) <= n ) {
bool k = 0 ;
int change = 1 << i ;
for ( int j = 0 ;
j <= n ;
j ++ ) {
ans += k ;
if ( change == 1 ) {
k = ! k ;
change = 1 << i ;
}
else {
change -- ;
}
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countSetBits ( int n ) {
int i = 0 ;
int ans = 0 ;
while ( ( 1 << i ) <= n ) {
boolean k = false ;
int change = 1 << i ;
for ( int j = 0 ;
j <= n ;
j ++ ) {
if ( k == true ) ans += 1 ;
else ans += 0 ;
if ( change == 1 ) {
k = ! k ;
change = 1... |
java-cpp-COUNT_PAIRS_WITH_GIVEN_SUM_1 | java-cpp | static int getPairsCount ( int n , int sum ) {
HashMap < Integer , Integer > hm = new HashMap < > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;
hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;
}
int twice_count = 0 ;
for ( int i ... | int getPairsCount ( int arr [ ] , int n , int sum ) {
unordered_map < int , int > m ;
for ( int i = 0 ;
i < n ;
i ++ ) m [ arr [ i ] ] ++ ;
int twice_count = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
twice_count += m [ sum - arr [ i ] ] ;
if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;
}
r... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int getPairsCount ( int n , int sum ) {
HashMap < Integer , Integer > hm = new HashMap < > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;
hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;
}
int twice_count = 0 ;
for (... |
java-cpp-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX | java-cpp | static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {
for ( int i = 0 ;
i < N ;
i ++ ) for ( int j = 0 ;
j < N ;
j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;
return true ;
}
| bool isDiagonalMatrix ( int mat [ N ] [ N ] ) {
for ( int i = 0 ;
i < N ;
i ++ ) for ( int j = 0 ;
j < N ;
j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {
for ( int i = 0 ;
i < N ;
i ++ ) for ( int j = 0 ;
j < N ;
j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;
return true ;
}
</Code> |
java-cpp-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION | java-cpp | static void printSorted ( int a , int b , int c ) {
int get_max = Math . max ( a , Math . max ( b , c ) ) ;
int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;
int get_mid = ( a + b + c ) - ( get_max + get_min ) ;
System . out . print ( get_min + " " + get_mid + " " + get_max ) ;
}
| void printSorted ( int a , int b , int c ) {
int get_max = max ( a , max ( b , c ) ) ;
int get_min = - max ( - a , max ( - b , - c ) ) ;
int get_mid = ( a + b + c ) - ( get_max + get_min ) ;
cout << get_min << " " << get_mid << " " << get_max ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void printSorted ( int a , int b , int c ) {
int get_max = Math . max ( a , Math . max ( b , c ) ) ;
int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;
int get_mid = ( a + b + c ) - ( get_max + get_min ) ;
System . out . print ( get_min + " " + get_mid + " " + get_max ) ;
}
</Code> |
java-cpp-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT | java-cpp | static boolean isDivisible ( long n ) {
while ( n / 100 > 0 ) {
int last_digit = ( int ) n % 10 ;
n /= 10 ;
n += last_digit * 3 ;
}
return ( n % 29 == 0 ) ;
}
| bool isDivisible ( long long int n ) {
while ( n / 100 ) {
int last_digit = n % 10 ;
n /= 10 ;
n += last_digit * 3 ;
}
return ( n % 29 == 0 ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isDivisible ( long n ) {
while ( n / 100 > 0 ) {
int last_digit = ( int ) n % 10 ;
n /= 10 ;
n += last_digit * 3 ;
}
return ( n % 29 == 0 ) ;
}
</Code> |
java-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE | java-cpp | static int getSingle ( int arr [ ] , int n ) {
int ones = 0 , twos = 0 ;
int common_bit_mask ;
for ( int i = 0 ;
i < n ;
i ++ ) {
twos = twos | int getSingle ( int arr [ ] , int n ) {
int ones = 0 , twos = 0 ;
int common_bit_mask ;
for ( int i = 0 ;
i < n ;
i ++ ) {
twos = twos | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int getSingle ( int arr [ ] , int n ) {
int ones = 0 , twos = 0 ;
int common_bit_mask ;
for ( int i = 0 ;
i < n ;
i ++ ) {
twos = twos
</Code> |
java-cpp-MINIMUM_SUM_PATH_TRIANGLE | java-cpp | static int minSumPath ( ) {
int [ ] memo = new int [ A . length ] ;
int n = A . length - 1 ;
for ( int i = 0 ;
i < A [ n ] . length ;
i ++ ) memo [ i ] = A [ n ] [ i ] ;
for ( int i = A . length - 2 ;
i >= 0 ;
i -- ) for ( int j = 0 ;
j < A [ i ] . length ;
j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ... | int minSumPath ( vector < vector < int >> & A ) {
int memo [ A . size ( ) ] ;
int n = A . size ( ) - 1 ;
for ( int i = 0 ;
i < A [ n ] . size ( ) ;
i ++ ) memo [ i ] = A [ n ] [ i ] ;
for ( int i = A . size ( ) - 2 ;
i >= 0 ;
i -- ) for ( int j = 0 ;
j < A [ i ] . size ( ) ;
j ++ ) memo [ j ] = A [ ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int minSumPath ( ) {
int [ ] memo = new int [ A . length ] ;
int n = A . length - 1 ;
for ( int i = 0 ;
i < A [ n ] . length ;
i ++ ) memo [ i ] = A [ n ] [ i ] ;
for ( int i = A . length - 2 ;
i >= 0 ;
i -- ) for ( int j = 0 ;
j < A [ i ] . length ;
j ++ ) memo [ j ] = A [ i ] [ j ] +... |
java-cpp-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH | java-cpp | static void rearrange ( int arr [ ] , int n ) {
int i = - 1 , temp = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( arr [ j ] < 0 ) {
i ++ ;
temp = arr [ i ] ;
arr [ i ] = arr [ j ] ;
arr [ j ] = temp ;
}
}
int pos = i + 1 , neg = 0 ;
while ( pos < n && neg < pos && arr [ neg ... | void GFG :: rearrange ( int arr [ ] , int n ) {
int i = - 1 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( arr [ j ] < 0 ) {
i ++ ;
swap ( & arr [ i ] , & arr [ j ] ) ;
}
}
int pos = i + 1 , neg = 0 ;
while ( pos < n && neg < pos && arr [ neg ] < 0 ) {
swap ( & arr [ neg ] , & arr [ pos... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void rearrange ( int arr [ ] , int n ) {
int i = - 1 , temp = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( arr [ j ] < 0 ) {
i ++ ;
temp = arr [ i ] ;
arr [ i ] = arr [ j ] ;
arr [ j ] = temp ;
}
}
int pos = i + 1 , neg = 0 ;
while ( pos < n && neg < pos && arr... |
java-cpp-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY | java-cpp | static int countNum ( int [ ] arr , int n ) {
int count = 0 ;
Arrays . sort ( arr ) ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;
return count ;
}
| int countNum ( int arr [ ] , int n ) {
int count = 0 ;
sort ( arr , arr + n ) ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;
return count ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countNum ( int [ ] arr , int n ) {
int count = 0 ;
Arrays . sort ( arr ) ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;
return count ;
}
</Code> |
java-cpp-LARGEST_SUBSEQUENCE_GCD_GREATER_1 | java-cpp | static int largestGCDSubsequence ( int arr [ ] , int n ) {
int ans = 0 ;
int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;
;
for ( int i = 2 ;
i <= maxele ;
++ i ) {
int count = 0 ;
for ( int j = 0 ;
j < n ;
++ j ) {
if ( arr [ j ] % i == 0 ) ++ count ;
}
ans = Ma... | int largestGCDSubsequence ( int arr [ ] , int n ) {
int ans = 0 ;
int maxele = * max_element ( arr , arr + n ) ;
for ( int i = 2 ;
i <= maxele ;
++ i ) {
int count = 0 ;
for ( int j = 0 ;
j < n ;
++ j ) {
if ( arr [ j ] % i == 0 ) ++ count ;
}
ans = max ( ans , count ) ;
}
re... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int largestGCDSubsequence ( int arr [ ] , int n ) {
int ans = 0 ;
int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;
;
for ( int i = 2 ;
i <= maxele ;
++ i ) {
int count = 0 ;
for ( int j = 0 ;
j < n ;
++ j ) {
if ( arr [ j ] % i == 0 ) ++ count ;
}
a... |
java-cpp-PROGRAM_CHECK_INPUT_INTEGER_STRING | java-cpp | static boolean isNumber ( String s ) {
for ( int i = 0 ;
i < s . length ( ) ;
i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;
return true ;
}
| bool isNumber ( string s ) {
for ( int i = 0 ;
i < s . length ( ) ;
i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isNumber ( String s ) {
for ( int i = 0 ;
i < s . length ( ) ;
i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;
return true ;
}
</Code> |
java-cpp-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1 | java-cpp | static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {
int count = 0 ;
HashSet < Integer > us = new HashSet < Integer > ( ) ;
for ( int i = 0 ;
i < m ;
i ++ ) us . add ( arr1 [ i ] ) ;
for ( int j = 0 ;
j < n ;
j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;
return c... | int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {
int count = 0 ;
unordered_set < int > us ;
for ( int i = 0 ;
i < m ;
i ++ ) us . insert ( arr1 [ i ] ) ;
for ( int j = 0 ;
j < n ;
j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;
return count ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {
int count = 0 ;
HashSet < Integer > us = new HashSet < Integer > ( ) ;
for ( int i = 0 ;
i < m ;
i ++ ) us . add ( arr1 [ i ] ) ;
for ( int j = 0 ;
j < n ;
j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;
r... |
java-cpp-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS | java-cpp | static int countSquares ( int a , int b ) {
int cnt = 0 ;
for ( int i = a ;
i <= b ;
i ++ ) for ( int j = 1 ;
j * j <= i ;
j ++ ) if ( j * j == i ) cnt ++ ;
return cnt ;
}
| int countSquares ( int a , int b ) {
int cnt = 0 ;
for ( int i = a ;
i <= b ;
i ++ ) for ( int j = 1 ;
j * j <= i ;
j ++ ) if ( j * j == i ) cnt ++ ;
return cnt ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countSquares ( int a , int b ) {
int cnt = 0 ;
for ( int i = a ;
i <= b ;
i ++ ) for ( int j = 1 ;
j * j <= i ;
j ++ ) if ( j * j == i ) cnt ++ ;
return cnt ;
}
</Code> |
java-cpp-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N | java-cpp | static int minSum ( int n ) {
int sum = 0 ;
while ( n > 0 ) {
sum += ( n % 10 ) ;
n /= 10 ;
}
if ( sum == 1 ) return 10 ;
return sum ;
}
| int minSum ( int n ) {
int sum = 0 ;
while ( n > 0 ) {
sum += ( n % 10 ) ;
n /= 10 ;
}
if ( sum == 1 ) return 10 ;
return sum ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int minSum ( int n ) {
int sum = 0 ;
while ( n > 0 ) {
sum += ( n % 10 ) ;
n /= 10 ;
}
if ( sum == 1 ) return 10 ;
return sum ;
}
</Code> |
java-cpp-NTH_NON_FIBONACCI_NUMBER | java-cpp | static int nonFibonacci ( int n ) {
int prevPrev = 1 , prev = 2 , curr = 3 ;
while ( n > 0 ) {
prevPrev = prev ;
prev = curr ;
curr = prevPrev + prev ;
n = n - ( curr - prev - 1 ) ;
}
n = n + ( curr - prev - 1 ) ;
return prev + n ;
}
| int nonFibonacci ( int n ) {
int prevPrev = 1 , prev = 2 , curr = 3 ;
while ( n > 0 ) {
prevPrev = prev ;
prev = curr ;
curr = prevPrev + prev ;
n = n - ( curr - prev - 1 ) ;
}
n = n + ( curr - prev - 1 ) ;
return prev + n ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int nonFibonacci ( int n ) {
int prevPrev = 1 , prev = 2 , curr = 3 ;
while ( n > 0 ) {
prevPrev = prev ;
prev = curr ;
curr = prevPrev + prev ;
n = n - ( curr - prev - 1 ) ;
}
n = n + ( curr - prev - 1 ) ;
return prev + n ;
}
</Code> |
java-cpp-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1 | java-cpp | static int lis ( int arr [ ] , int n ) {
int lis [ ] = new int [ n ] ;
int i , j , max = 0 ;
for ( i = 0 ;
i < n ;
i ++ ) lis [ i ] = 1 ;
for ( i = 1 ;
i < n ;
i ++ ) for ( j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
for ( i = 0 ;
... | int lis ( int arr [ ] , int n ) {
int lis [ n ] ;
lis [ 0 ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
lis [ i ] = 1 ;
for ( int j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
}
return * max_element ( lis , lis + n ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int lis ( int arr [ ] , int n ) {
int lis [ ] = new int [ n ] ;
int i , j , max = 0 ;
for ( i = 0 ;
i < n ;
i ++ ) lis [ i ] = 1 ;
for ( i = 1 ;
i < n ;
i ++ ) for ( j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;
for ( i =... |
java-cpp-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY | java-cpp | static void leftRotate ( int arr [ ] , int n , int k ) {
for ( int i = k ;
i < k + n ;
i ++ ) System . out . print ( arr [ i % n ] + " " ) ;
}
| void leftRotate ( int arr [ ] , int n , int k ) {
for ( int i = k ;
i < k + n ;
i ++ ) cout << arr [ i % n ] << " " ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void leftRotate ( int arr [ ] , int n , int k ) {
for ( int i = k ;
i < k + n ;
i ++ ) System . out . print ( arr [ i % n ] + " " ) ;
}
</Code> |
java-cpp-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES | java-cpp | static String repeat ( String s , int n ) {
String s1 = s ;
for ( int i = 1 ;
i < n ;
i ++ ) s += s1 ;
return s ;
}
| string repeat ( string s , int n ) {
string s1 = s ;
for ( int i = 1 ;
i < n ;
i ++ ) s += s1 ;
return s ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static String repeat ( String s , int n ) {
String s1 = s ;
for ( int i = 1 ;
i < n ;
i ++ ) s += s1 ;
return s ;
}
</Code> |
java-cpp-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING | java-cpp | static String findSubString ( String str ) {
int n = str . length ( ) ;
int dist_count = 0 ;
boolean [ ] visited = new boolean [ MAX_CHARS ] ;
Arrays . fill ( visited , false ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( visited [ str . charAt ( i ) ] == false ) {
visited [ str . charAt ( i ) ] = ... | string findSubString ( string str ) {
int n = str . length ( ) ;
int dist_count = 0 ;
bool visited [ MAX_CHARS ] = {
false }
;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( visited [ str [ i ] ] == false ) {
visited [ str [ i ] ] = true ;
dist_count ++ ;
}
}
int s... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static String findSubString ( String str ) {
int n = str . length ( ) ;
int dist_count = 0 ;
boolean [ ] visited = new boolean [ MAX_CHARS ] ;
Arrays . fill ( visited , false ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( visited [ str . charAt ( i ) ] == false ) {
visited [ str . charAt ( i... |
java-cpp-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3 | java-cpp | public static int findStep ( int n ) {
if ( n == 1 || n == 0 ) return 1 ;
else if ( n == 2 ) return 2 ;
else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;
}
| public : int findStep ( int n ) {
if ( n == 1 || n == 0 ) return 1 ;
else if ( n == 2 ) return 2 ;
else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static int findStep ( int n ) {
if ( n == 1 || n == 0 ) return 1 ;
else if ( n == 2 ) return 2 ;
else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;
}
</Code> |
java-cpp-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1 | java-cpp | static void printSubsequences ( int n ) {
int opsize = ( int ) Math . pow ( 2 , n ) ;
for ( int counter = 1 ;
counter < opsize ;
counter ++ ) {
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + " " ) ;
}
System... | void printSubsequences ( int arr [ ] , int n ) {
unsigned int opsize = pow ( 2 , n ) ;
for ( int counter = 1 ;
counter < opsize ;
counter ++ ) {
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( counter & ( 1 << j ) ) cout << arr [ j ] << " " ;
}
cout << endl ;
}
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void printSubsequences ( int n ) {
int opsize = ( int ) Math . pow ( 2 , n ) ;
for ( int counter = 1 ;
counter < opsize ;
counter ++ ) {
for ( int j = 0 ;
j < n ;
j ++ ) {
if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + " " ) ;
}
... |
java-cpp-MINIMUM_XOR_VALUE_PAIR_1 | java-cpp | static int minXOR ( int arr [ ] , int n ) {
Arrays . parallelSort ( arr ) ;
int minXor = Integer . MAX_VALUE ;
int val = 0 ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
val = arr [ i ] ^ arr [ i + 1 ] ;
minXor = Math . min ( minXor , val ) ;
}
return minXor ;
}
| int minXOR ( int arr [ ] , int n ) {
sort ( arr , arr + n ) ;
int minXor = INT_MAX ;
int val = 0 ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
val = arr [ i ] ^ arr [ i + 1 ] ;
minXor = min ( minXor , val ) ;
}
return minXor ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int minXOR ( int arr [ ] , int n ) {
Arrays . parallelSort ( arr ) ;
int minXor = Integer . MAX_VALUE ;
int val = 0 ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
val = arr [ i ] ^ arr [ i + 1 ] ;
minXor = Math . min ( minXor , val ) ;
}
return minXor ;
}
</Code> |
java-cpp-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION | java-cpp | static void luDecomposition ( int [ ] [ ] mat , int n ) {
int [ ] [ ] lower = new int [ n ] [ n ] ;
int [ ] [ ] upper = new int [ n ] [ n ] ;
for ( int i = 0 ;
i < n ;
i ++ ) {
for ( int k = i ;
k < n ;
k ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < i ;
j ++ ) sum += ( lower ... | void luDecomposition ( int mat [ ] [ MAX ] , int n ) {
int lower [ n ] [ n ] , upper [ n ] [ n ] ;
memset ( lower , 0 , sizeof ( lower ) ) ;
memset ( upper , 0 , sizeof ( upper ) ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
for ( int k = i ;
k < n ;
k ++ ) {
int sum = 0 ;
for ( int j = 0 ;... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void luDecomposition ( int [ ] [ ] mat , int n ) {
int [ ] [ ] lower = new int [ n ] [ n ] ;
int [ ] [ ] upper = new int [ n ] [ n ] ;
for ( int i = 0 ;
i < n ;
i ++ ) {
for ( int k = i ;
k < n ;
k ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < i ;
j ++ ) sum += (... |
java-cpp-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1 | java-cpp | static void bin ( Integer n ) {
if ( n > 1 ) bin ( n >> 1 ) ;
System . out . printf ( "%d" , n & 1 ) ;
}
| void bin ( unsigned n ) {
if ( n > 1 ) bin ( n >> 1 ) ;
printf ( "%d" , n & 1 ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void bin ( Integer n ) {
if ( n > 1 ) bin ( n >> 1 ) ;
System . out . printf ( "%d" , n & 1 ) ;
}
</Code> |
java-cpp-COUNT_PALINDROME_SUB_STRINGS_STRING | java-cpp | static int CountPS ( char str [ ] , int n ) {
int dp [ ] [ ] = new int [ n ] [ n ] ;
boolean P [ ] [ ] = new boolean [ n ] [ n ] ;
for ( int i = 0 ;
i < n ;
i ++ ) P [ i ] [ i ] = true ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
if ( str [ i ] == str [ i + 1 ] ) {
P [ i ] [ i + 1 ] = true ;
... | int CountPS ( char str [ ] , int n ) {
int dp [ n ] [ n ] ;
memset ( dp , 0 , sizeof ( dp ) ) ;
bool P [ n ] [ n ] ;
memset ( P , false , sizeof ( P ) ) ;
for ( int i = 0 ;
i < n ;
i ++ ) P [ i ] [ i ] = true ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
if ( str [ i ] == str [ i + 1 ] ) {
P [ ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int CountPS ( char str [ ] , int n ) {
int dp [ ] [ ] = new int [ n ] [ n ] ;
boolean P [ ] [ ] = new boolean [ n ] [ n ] ;
for ( int i = 0 ;
i < n ;
i ++ ) P [ i ] [ i ] = true ;
for ( int i = 0 ;
i < n - 1 ;
i ++ ) {
if ( str [ i ] == str [ i + 1 ] ) {
P [ i ] [ i + 1 ] = true ... |
java-cpp-GIVEN_TWO_NUMBERS_B_FIND_X_X_B | java-cpp | static void modularEquation ( int a , int b ) {
if ( a < b ) {
System . out . println ( "No solution possible " ) ;
return ;
}
if ( a == b ) {
System . out . println ( "Infinite Solution possible " ) ;
return ;
}
int count = 0 ;
int n = a - b ;
int y = ( int ) Math . sqrt ( a - b ) ;
for... | void modularEquation ( int a , int b ) {
if ( a < b ) {
cout << "No solution possible " << endl ;
return ;
}
if ( a == b ) {
cout << "Infinite Solution possible " << endl ;
return ;
}
int count = 0 ;
int n = a - b ;
int y = sqrt ( a - b ) ;
for ( int i = 1 ;
i <= y ;
++ i ) {
if ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void modularEquation ( int a , int b ) {
if ( a < b ) {
System . out . println ( "No solution possible " ) ;
return ;
}
if ( a == b ) {
System . out . println ( "Infinite Solution possible " ) ;
return ;
}
int count = 0 ;
int n = a - b ;
int y = ( int ) Math . sqrt ( a - b ) ... |
java-cpp-PAPER_CUT_MINIMUM_NUMBER_SQUARES | java-cpp | static int minimumSquare ( int a , int b ) {
int result = 0 , rem = 0 ;
if ( a < b ) swap ( a , b ) ;
while ( b > 0 ) {
result += a / b ;
rem = a % b ;
a = b ;
b = rem ;
}
return result ;
}
| int minimumSquare ( int a , int b ) {
long long result = 0 , rem = 0 ;
if ( a < b ) swap ( a , b ) ;
while ( b > 0 ) {
result += a / b ;
long long rem = a % b ;
a = b ;
b = rem ;
}
return result ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int minimumSquare ( int a , int b ) {
int result = 0 , rem = 0 ;
if ( a < b ) swap ( a , b ) ;
while ( b > 0 ) {
result += a / b ;
rem = a % b ;
a = b ;
b = rem ;
}
return result ;
}
</Code> |
java-cpp-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM | java-cpp | static int maxSum ( int [ ] [ ] mat , int n ) {
if ( n == 1 ) return mat [ 0 ] [ 0 ] ;
int dp [ ] [ ] = new int [ n ] [ n ] ;
int maxSum = Integer . MIN_VALUE , max ;
for ( int j = 0 ;
j < n ;
j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;
for ( int i = n - 2 ;
i >= 0 ;
i -- ) {
for ( int j = 0... | int maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {
if ( n == 1 ) return mat [ 0 ] [ 0 ] ;
int dp [ n ] [ n ] ;
int maxSum = INT_MIN , max ;
for ( int j = 0 ;
j < n ;
j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;
for ( int i = n - 2 ;
i >= 0 ;
i -- ) {
for ( int j = 0 ;
j < n ;
j ++ ) {... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maxSum ( int [ ] [ ] mat , int n ) {
if ( n == 1 ) return mat [ 0 ] [ 0 ] ;
int dp [ ] [ ] = new int [ n ] [ n ] ;
int maxSum = Integer . MIN_VALUE , max ;
for ( int j = 0 ;
j < n ;
j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;
for ( int i = n - 2 ;
i >= 0 ;
i -- ) {
for ( in... |
java-cpp-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS | java-cpp | static long findMinSum ( long a [ ] , long b [ ] , long n ) {
Arrays . sort ( a ) ;
Arrays . sort ( b ) ;
long sum = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;
return sum ;
}
| long long int findMinSum ( int a [ ] , int b [ ] , int n ) {
sort ( a , a + n ) ;
sort ( b , b + n ) ;
long long int sum = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;
return sum ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static long findMinSum ( long a [ ] , long b [ ] , long n ) {
Arrays . sort ( a ) ;
Arrays . sort ( b ) ;
long sum = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;
return sum ;
}
</Code> |
java-cpp-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER | java-cpp | static void deleteElements ( int arr [ ] , int n , int k ) {
Stack < Integer > s = new Stack < > ( ) ;
s . push ( arr [ 0 ] ) ;
int count = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {
s . pop ( ) ;
count ++ ;
}
s . push ... | void deleteElements ( int arr [ ] , int n , int k ) {
stack < int > s ;
s . push ( arr [ 0 ] ) ;
int count = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {
s . pop ( ) ;
count ++ ;
}
s . push ( arr [ i ] ) ;
}
int m = s ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void deleteElements ( int arr [ ] , int n , int k ) {
Stack < Integer > s = new Stack < > ( ) ;
s . push ( arr [ 0 ] ) ;
int count = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {
s . pop ( ) ;
count ++ ;
}
s ... |
java-cpp-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE | java-cpp | static char first ( String str ) {
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;
return 0 ;
}
| char first ( string str ) {
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;
return 0 ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static char first ( String str ) {
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;
return 0 ;
}
</Code> |
java-cpp-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS | java-cpp | int minDist ( int arr [ ] , int n , int x , int y ) {
int i , j ;
int min_dist = Integer . MAX_VALUE ;
for ( i = 0 ;
i < n ;
i ++ ) {
for ( j = i + 1 ;
j < n ;
j ++ ) {
if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist... | int minDist ( int arr [ ] , int n , int x , int y ) {
int i , j ;
int min_dist = INT_MAX ;
for ( i = 0 ;
i < n ;
i ++ ) {
for ( j = i + 1 ;
j < n ;
j ++ ) {
if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {
min_dist = abs ( ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
int minDist ( int arr [ ] , int n , int x , int y ) {
int i , j ;
int min_dist = Integer . MAX_VALUE ;
for ( i = 0 ;
i < n ;
i ++ ) {
for ( j = i + 1 ;
j < n ;
j ++ ) {
if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) m... |
java-cpp-ARC_LENGTH_ANGLE | java-cpp | static double arcLength ( double diameter , double angle ) {
double pi = 22.0 / 7.0 ;
double arc ;
if ( angle >= 360 ) {
System . out . println ( "Angle cannot" + " be formed" ) ;
return 0 ;
}
else {
arc = ( pi * diameter ) * ( angle / 360.0 ) ;
return arc ;
}
}
| double arcLength ( double diameter , double angle ) {
double pi = 22.0 / 7.0 ;
double arc ;
if ( angle >= 360 ) {
cout << "Angle cannot" , " be formed" ;
return 0 ;
}
else {
arc = ( pi * diameter ) * ( angle / 360.0 ) ;
return arc ;
}
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static double arcLength ( double diameter , double angle ) {
double pi = 22.0 / 7.0 ;
double arc ;
if ( angle >= 360 ) {
System . out . println ( "Angle cannot" + " be formed" ) ;
return 0 ;
}
else {
arc = ( pi * diameter ) * ( angle / 360.0 ) ;
return arc ;
}
}
</Code> |
java-cpp-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT | java-cpp | static void findSymPairs ( int arr [ ] [ ] ) {
HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;
for ( int i = 0 ;
i < arr . length ;
i ++ ) {
int first = arr [ i ] [ 0 ] ;
int sec = arr [ i ] [ 1 ] ;
Integer val = hM . get ( sec ) ;
if ( val != null && val == first ) Sy... | void findSymPairs ( int arr [ ] [ 2 ] , int row ) {
unordered_map < int , int > hM ;
for ( int i = 0 ;
i < row ;
i ++ ) {
int first = arr [ i ] [ 0 ] ;
int sec = arr [ i ] [ 1 ] ;
if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << "(" << sec << ", " << first << ")" << endl ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void findSymPairs ( int arr [ ] [ ] ) {
HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;
for ( int i = 0 ;
i < arr . length ;
i ++ ) {
int first = arr [ i ] [ 0 ] ;
int sec = arr [ i ] [ 1 ] ;
Integer val = hM . get ( sec ) ;
if ( val != null && val == fir... |
java-cpp-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED | java-cpp | static boolean isValidString ( String str ) {
int freq [ ] = new int [ CHARS ] ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
freq [ str . charAt ( i ) - ' a ' ] ++ ;
}
int i , freq1 = 0 , count_freq1 = 0 ;
for ( i = 0 ;
i < CHARS ;
i ++ ) {
if ( freq [ i ] != 0 ) {
freq1 = freq [ i... | bool isValidString ( string str ) {
int freq [ CHARS ] = {
0 }
;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) freq [ str [ i ] - 'a' ] ++ ;
int i , freq1 = 0 , count_freq1 = 0 ;
for ( i = 0 ;
i < CHARS ;
i ++ ) {
if ( freq [ i ] != 0 ) {
freq1 = freq [ i ] ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isValidString ( String str ) {
int freq [ ] = new int [ CHARS ] ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
freq [ str . charAt ( i ) - ' a ' ] ++ ;
}
int i , freq1 = 0 , count_freq1 = 0 ;
for ( i = 0 ;
i < CHARS ;
i ++ ) {
if ( freq [ i ] != 0 ) {
freq1 = f... |
java-cpp-PRIME_NUMBERS | java-cpp | static boolean isPrime ( int n ) {
if ( n <= 1 ) return false ;
for ( int i = 2 ;
i < n ;
i ++ ) if ( n % i == 0 ) return false ;
return true ;
}
| bool isPrime ( int n ) {
if ( n <= 1 ) return false ;
for ( int i = 2 ;
i < n ;
i ++ ) if ( n % i == 0 ) return false ;
return true ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static boolean isPrime ( int n ) {
if ( n <= 1 ) return false ;
for ( int i = 2 ;
i < n ;
i ++ ) if ( n % i == 0 ) return false ;
return true ;
}
</Code> |
java-cpp-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH | java-cpp | static int findMaxAverage ( int [ ] arr , int n , int k ) {
if ( k > n ) return - 1 ;
int [ ] csum = new int [ n ] ;
csum [ 0 ] = arr [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;
int max_sum = csum [ k - 1 ] , max_end = k - 1 ;
for ( int i = k ;
i < n ;
i ++ ) {... | int findMaxAverage ( int arr [ ] , int n , int k ) {
if ( k > n ) return - 1 ;
int * csum = new int [ n ] ;
csum [ 0 ] = arr [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;
int max_sum = csum [ k - 1 ] , max_end = k - 1 ;
for ( int i = k ;
i < n ;
i ++ ) {
int ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int findMaxAverage ( int [ ] arr , int n , int k ) {
if ( k > n ) return - 1 ;
int [ ] csum = new int [ n ] ;
csum [ 0 ] = arr [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;
int max_sum = csum [ k - 1 ] , max_end = k - 1 ;
for ( int i = k ;
i < n ;
i... |
java-cpp-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM | java-cpp | static void maximizecube ( int l , int b , int h ) {
int side = gcd ( l , gcd ( b , h ) ) ;
int num = l / side ;
num = ( num * b / side ) ;
num = ( num * h / side ) ;
System . out . println ( side + " " + num ) ;
}
| void maximizecube ( int l , int b , int h ) {
int side = __gcd ( l , __gcd ( b , h ) ) ;
int num = l / side ;
num = ( num * b / side ) ;
num = ( num * h / side ) ;
cout << side << " " << num << endl ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void maximizecube ( int l , int b , int h ) {
int side = gcd ( l , gcd ( b , h ) ) ;
int num = l / side ;
num = ( num * b / side ) ;
num = ( num * h / side ) ;
System . out . println ( side + " " + num ) ;
}
</Code> |
java-cpp-HORNERS_METHOD_POLYNOMIAL_EVALUATION | java-cpp | static int horner ( int poly [ ] , int n , int x ) {
int result = poly [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) result = result * x + poly [ i ] ;
return result ;
}
| int horner ( int poly [ ] , int n , int x ) {
int result = poly [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) result = result * x + poly [ i ] ;
return result ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int horner ( int poly [ ] , int n , int x ) {
int result = poly [ 0 ] ;
for ( int i = 1 ;
i < n ;
i ++ ) result = result * x + poly [ i ] ;
return result ;
}
</Code> |
java-cpp-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE | java-cpp | static void rotate ( ) {
int x = arr [ arr . length - 1 ] , i ;
for ( i = arr . length - 1 ;
i > 0 ;
i -- ) arr [ i ] = arr [ i - 1 ] ;
arr [ 0 ] = x ;
}
| void rotate ( int arr [ ] , int n ) {
int x = arr [ n - 1 ] , i ;
for ( i = n - 1 ;
i > 0 ;
i -- ) arr [ i ] = arr [ i - 1 ] ;
arr [ 0 ] = x ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void rotate ( ) {
int x = arr [ arr . length - 1 ] , i ;
for ( i = arr . length - 1 ;
i > 0 ;
i -- ) arr [ i ] = arr [ i - 1 ] ;
arr [ 0 ] = x ;
}
</Code> |
java-cpp-N_BONACCI_NUMBERS_1 | java-cpp | static void bonacciseries ( int n , int m ) {
int a [ ] = new int [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) a [ i ] = 0 ;
a [ n - 1 ] = 1 ;
a [ n ] = 1 ;
for ( int i = n + 1 ;
i < m ;
i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;
for ( int i = 0 ;
i < m ;
i ++ ) System . out . print ( a [ ... | void bonacciseries ( long n , int m ) {
int a [ m ] = {
0 }
;
a [ n - 1 ] = 1 ;
a [ n ] = 1 ;
for ( int i = n + 1 ;
i < m ;
i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;
for ( int i = 0 ;
i < m ;
i ++ ) cout << a [ i ] << " " ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void bonacciseries ( int n , int m ) {
int a [ ] = new int [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) a [ i ] = 0 ;
a [ n - 1 ] = 1 ;
a [ n ] = 1 ;
for ( int i = n + 1 ;
i < m ;
i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;
for ( int i = 0 ;
i < m ;
i ++ ) System . out . print... |
java-cpp-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1 | java-cpp | static int numberOfWays ( int x ) {
int dp [ ] = new int [ x + 1 ] ;
dp [ 0 ] = dp [ 1 ] = 1 ;
for ( int i = 2 ;
i <= x ;
i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;
return dp [ x ] ;
}
| int numberOfWays ( int x ) {
int dp [ x + 1 ] ;
dp [ 0 ] = dp [ 1 ] = 1 ;
for ( int i = 2 ;
i <= x ;
i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;
return dp [ x ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int numberOfWays ( int x ) {
int dp [ ] = new int [ x + 1 ] ;
dp [ 0 ] = dp [ 1 ] = 1 ;
for ( int i = 2 ;
i <= x ;
i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;
return dp [ x ] ;
}
</Code> |
java-cpp-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS | java-cpp | static int findoptimal ( int N ) {
if ( N <= 6 ) return N ;
int [ ] screen = new int [ N ] ;
int b ;
int n ;
for ( n = 1 ;
n <= 6 ;
n ++ ) screen [ n - 1 ] = n ;
for ( n = 7 ;
n <= N ;
n ++ ) {
screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen ... | int findoptimal ( int N ) {
if ( N <= 6 ) return N ;
int screen [ N ] ;
int b ;
int n ;
for ( n = 1 ;
n <= 6 ;
n ++ ) screen [ n - 1 ] = n ;
for ( n = 7 ;
n <= N ;
n ++ ) {
screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;
}
return screen... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int findoptimal ( int N ) {
if ( N <= 6 ) return N ;
int [ ] screen = new int [ N ] ;
int b ;
int n ;
for ( n = 1 ;
n <= 6 ;
n ++ ) screen [ n - 1 ] = n ;
for ( n = 7 ;
n <= N ;
n ++ ) {
screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * ... |
java-cpp-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX | java-cpp | static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {
int rowSum [ ] = new int [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += mat [ i ] [ j ] ;
rowSum [ i ] = sum ;
}
int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;
int min_element = ... | int maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {
int rowSum [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += mat [ i ] [ j ] ;
rowSum [ i ] = sum ;
}
int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;
int min_element = rowSum [ 0 ] ;
... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {
int rowSum [ ] = new int [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) {
int sum = 0 ;
for ( int j = 0 ;
j < n ;
j ++ ) sum += mat [ i ] [ j ] ;
rowSum [ i ] = sum ;
}
int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;
int min_ele... |
java-cpp-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1 | java-cpp | static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {
modulo = ( ( modulo % M ) + M ) % M ;
if ( index == n ) {
if ( modulo == 0 ) {
return 1 ;
}
return 0 ;
}
if ( dp [ index ] [ modulo ] != - 1 ) {
return dp [ index ] [ modulo ] ;
}
int plac... | int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {
modulo = ( ( modulo % M ) + M ) % M ;
if ( index == n ) {
if ( modulo == 0 ) return 1 ;
return 0 ;
}
if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;
int placeAdd = isPossible ( n , ind... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {
modulo = ( ( modulo % M ) + M ) % M ;
if ( index == n ) {
if ( modulo == 0 ) {
return 1 ;
}
return 0 ;
}
if ( dp [ index ] [ modulo ] != - 1 ) {
return dp [ index ] [ modulo ] ;
}
i... |
java-cpp-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO | java-cpp | static int fib ( int n ) {
if ( n < 6 ) return f [ n ] ;
int t = 5 ;
int fn = 5 ;
while ( t < n ) {
fn = ( int ) Math . round ( fn * PHI ) ;
t ++ ;
}
return fn ;
}
| int fib ( int n ) {
if ( n < 6 ) return f [ n ] ;
int t = 5 , fn = 5 ;
while ( t < n ) {
fn = round ( fn * PHI ) ;
t ++ ;
}
return fn ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int fib ( int n ) {
if ( n < 6 ) return f [ n ] ;
int t = 5 ;
int fn = 5 ;
while ( t < n ) {
fn = ( int ) Math . round ( fn * PHI ) ;
t ++ ;
}
return fn ;
}
</Code> |
java-cpp-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH | java-cpp | private static int minCost ( int cost [ ] [ ] , int m , int n ) {
int i , j ;
int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;
tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;
for ( i = 1 ;
i <= m ;
i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;
for ( j = 1 ;
j <= n ;
j ++ ) tc [ 0 ] [ j ] = tc [ 0 ... | int minCost ( int cost [ R ] [ C ] , int m , int n ) {
int i , j ;
int tc [ R ] [ C ] ;
tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;
for ( i = 1 ;
i <= m ;
i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;
for ( j = 1 ;
j <= n ;
j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;
fo... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
private static int minCost ( int cost [ ] [ ] , int m , int n ) {
int i , j ;
int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;
tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;
for ( i = 1 ;
i <= m ;
i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;
for ( j = 1 ;
j <= n ;
j ++ ) tc [ 0 ] [ j ] = ... |
java-cpp-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS | java-cpp | public static void amendSentence ( String sstr ) {
char [ ] str = sstr . toCharArray ( ) ;
for ( int i = 0 ;
i < str . length ;
i ++ ) {
if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {
str [ i ] = ( char ) ( str [ i ] + 32 ) ;
if ( i != 0 ) System . out . print ( " " ) ;
System . out . p... | void amendSentence ( string str ) {
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {
str [ i ] = str [ i ] + 32 ;
if ( i != 0 ) cout << " " ;
cout << str [ i ] ;
}
else cout << str [ i ] ;
}
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
public static void amendSentence ( String sstr ) {
char [ ] str = sstr . toCharArray ( ) ;
for ( int i = 0 ;
i < str . length ;
i ++ ) {
if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {
str [ i ] = ( char ) ( str [ i ] + 32 ) ;
if ( i != 0 ) System . out . print ( " " ) ;
System . ... |
java-cpp-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED | java-cpp | static int countWays ( int N ) {
int count [ ] = new int [ N + 1 ] ;
count [ 0 ] = 1 ;
for ( int i = 1 ;
i <= N ;
i ++ ) for ( int j = 0 ;
j < arr . length ;
j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;
return count [ N ] ;
}
| int countWays ( int arr [ ] , int m , int N ) {
int count [ N + 1 ] ;
memset ( count , 0 , sizeof ( count ) ) ;
count [ 0 ] = 1 ;
for ( int i = 1 ;
i <= N ;
i ++ ) for ( int j = 0 ;
j < m ;
j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;
return count [ N ] ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countWays ( int N ) {
int count [ ] = new int [ N + 1 ] ;
count [ 0 ] = 1 ;
for ( int i = 1 ;
i <= N ;
i ++ ) for ( int j = 0 ;
j < arr . length ;
j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;
return count [ N ] ;
}
</Code> |
java-cpp-BREAK_NUMBER_THREE_PARTS | java-cpp | static long count_of_ways ( long n ) {
long count = 0 ;
for ( int i = 0 ;
i <= n ;
i ++ ) for ( int j = 0 ;
j <= n ;
j ++ ) for ( int k = 0 ;
k <= n ;
k ++ ) if ( i + j + k == n ) count ++ ;
return count ;
}
| ll count_of_ways ( ll n ) {
ll count = 0 ;
for ( int i = 0 ;
i <= n ;
i ++ ) for ( int j = 0 ;
j <= n ;
j ++ ) for ( int k = 0 ;
k <= n ;
k ++ ) if ( i + j + k == n ) count ++ ;
return count ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static long count_of_ways ( long n ) {
long count = 0 ;
for ( int i = 0 ;
i <= n ;
i ++ ) for ( int j = 0 ;
j <= n ;
j ++ ) for ( int k = 0 ;
k <= n ;
k ++ ) if ( i + j + k == n ) count ++ ;
return count ;
}
</Code> |
java-cpp-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS | java-cpp | static double sumOfSeries ( int n ) {
return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;
}
| float sumOfSeries ( int n ) {
return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static double sumOfSeries ( int n ) {
return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;
}
</Code> |
java-cpp-PARTITION_NUMBER_TWO_DIVISBLE_PARTS | java-cpp | static void findDivision ( String str , int a , int b ) {
int len = str . length ( ) ;
int [ ] lr = new int [ len + 1 ] ;
lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;
for ( int i = 1 ;
i < len ;
i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' )... | void findDivision ( string & str , int a , int b ) {
int len = str . length ( ) ;
vector < int > lr ( len + 1 , 0 ) ;
lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;
for ( int i = 1 ;
i < len ;
i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;
vector < int > rl ( len + 1 , 0 ) ;
rl [ len ... | Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static void findDivision ( String str , int a , int b ) {
int len = str . length ( ) ;
int [ ] lr = new int [ len + 1 ] ;
lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;
for ( int i = 1 ;
i < len ;
i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ... |
java-cpp-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX | java-cpp | static int countCommon ( int mat [ ] [ ] , int n ) {
int res = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;
return res ;
}
| int countCommon ( int mat [ ] [ MAX ] , int n ) {
int res = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;
return res ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
static int countCommon ( int mat [ ] [ ] , int n ) {
int res = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;
return res ;
}
</Code> |
java-cpp-HEXAGONAL_NUMBER | java-cpp | int hexagonalNum ( int n ) {
return n * ( 2 * n - 1 ) ;
}
| int hexagonalNum ( int n ) {
return n * ( 2 * n - 1 ) ;
}
| Translate the given code from java to cpp. The input Code is marked with <Code> and </Code>. | <Code>
int hexagonalNum ( int n ) {
return n * ( 2 * n - 1 ) ;
}
</Code> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.