Jump to content

TheOne01

Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

1 Neutral

About TheOne01

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner( System.in ); int h = input.nextInt(); int m = input.nextInt(); whatTimeItIs(h, m); } public static void whatTimeItIs(int h, int m) { String[] hour = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", "eighteen", "nineteen"}; String result; boolean greater = false; if (m == 0) { result = hour[h-1] + " o' clock"; } else { if (m > 30) { m = 60 - m; greater = true; } if(m < 20) { result = hour[m - 1]; } else if (m == 30){ result = "half"; } else { result = m==20?"twenty":"twenty "+hour[m%10-1]; } if(m == 1){ result += " minute"; } else if(m != 15 && m != 30){ result += " minutes"; } if (!greater) { result += " past " + hour[h-1]; } else { result += " to "; if (h != 12) { result += hour[h]; } else { result += "one"; } } } System.out.println(result); } }
  2. Am si eu o intrebare: La 12:40 (de exemplu) ce ar trebui sa afiseze ?
  3. Nu cred ca la inceput era specificat ca cele doua jumatati sa fie egale. Oricum am inteles Multumesc !
  4. Salut, mi se pare mie sau algoritmul prezentat de theandruala nu merge chiar asa bine ? Mai sunt numere care sunt Kaprekar, dar nu sunt afisate: de exemplu 4879 #include <iostream> using namespace std; bool isKaprekar(uint64_t k) { uint64_t q, r, n = 10, kp = k*k; if(k == 1) return true; while(kp > n) { q = kp/n; r = kp%n; if(q + r == k && q > 0 && r > 0) return true; n *= 10; } return false; } int main() { uint64_t p, q, i; cin>>p>>q; for(i=p; i<=q; i++) if(isKaprekar(i)) cout<<i<<" "; return 0; }
×
×
  • Create New...