Answer the question
In order to leave comments, you need to log in
How to rewrite this program from C++ to Java?
In C, knowledge is practically zero, the main difficulties are caused by pointers and putchar. What analogs should be used in Java?
#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include "stdio.h"
using std::cout;
void find(char *pryamoy, char *centered, int size)
{
if (size == 0) return;
if (size == 1)
{
putchar(*pryamoy);
return;
}
char root = *pryamoy;
int findRoot = 0;
while (*centered != root)
{
++centered;
++findRoot;
}
find(pryamoy + 1, centered - findRoot, findRoot);
find(pryamoy + findRoot + 1, centered + 1, size - 1 - findRoot);
putchar(root);
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int tests;
scanf("%d\n", &tests);
char pryamoy[53],
centered[53];
for (int i = 0; i < tests; ++i)
{
int size;
scanf("%d %s %s", &size, pryamoy, centered);
find(pryamoy, centered, size);
printf("\n");
}
system("pause");
return 0;
Answer the question
In order to leave comments, you need to log in
Do you understand the search algorithm? If yes, then take it and implement it using java without being tied to analogues of C ++ functions. There is no simple analogue.
The putchar function writes the character at the current position to standard output (stdout) and moves the internal file pointer to the next position. In essence, in java, this is reading bytes of a file in a loop, with a byte written to a temporary buffer or output immediately to the standard output stream System.out.print(char);
Open the description of the functions in these two languages and if there is no one you need, recreate it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question