Search the Community
Showing results for tags 'unsigned'.
-
Salutare, Am urm?torul cod în C++ #include <fstream>#include <iostream> #include <math.h> using namespace std; bool pal(unsigned n) { unsigned x=n, inv=0; while (x>0) { inv = inv*10+x%10; x/=10; } return inv==n; } int main() { ifstream fin("test.in"); unsigned n; fin >> n; for (unsigned i=1;i<=n;i++) { unsigned a, b, rez=0; fin >> a >> b; if (pal(a)&&pal(int(sqrt(double(a))))) rez++; a=int(sqrt(double(a)))+1; b=int(sqrt(double()); while (a<= { if (pal(a) && pal(a*a)) rez++; a++; } cout << "Case #" << i << ": " << rez << endl; } return 0; } ?tiu c? putea fi scris ceva mai optimizat, ideea e c? am nevoie de acest cod în Java. M? poate ajuta cineva? ?i cam ce am f?cut eu: package palindrome;import java.util.*; public class palindrome { public static boolean pal(int n) { int x = n; int inv = 0; while (x > 0) { inv = inv * 10 + x % 10; x /= 10; } return inv == n; } public static int Main() { Scanner sc = new Scanner(new File("file.in")); int n = sc.nextInt(); for (int i = 1;i <= n;i++) { int rez = 0; int a = sc.nextInt(); int b = sc.nextInt(); if (palindrome.pal(a) && palindrome.pal((int)Math.sqrt((double)a))) { rez++; } a = (int)Math.sqrt((double)a) + 1; b = (int)Math.sqrt((double); while (a <= { if (palindrome.pal(a) && palindrome.pal(a * a)) { rez++; } a++; } System.out.print("Case #"); System.out.print(i); System.out.print(": "); System.out.print(rez); System.out.print("\n"); } return 0; } }