|
|
#include <bits/stdc++.h> string c[4] = {"88", "68", "06", "16"}; int main() { cin >> n; if (n > 4) { cout << "Glupenky Pierre" << endl; return 0; } for (int i = n - 1; i >= 0; i--) cout << c[i] << " "; } "68 88" is good, isn't? There are many more combinations. You also forgot 9 the main difficulty here was to understand that you need to use <string> #include <iostream> #include <string> using namespace std; int main() { int n; string arr[4] = { "16", "06", "68", "88" }; cin >> n; if (n <= 4) for (int i = 0; i < n; i++) { cout << arr[i] << " "; } else cout << "Glupenky Pierre"; } Edited by author 26.10.2018 11:42 Edited by author 26.10.2018 11:42 Text says "Pierre intends to use one-digit integers supplemented with a leading zero and two-digit integers only." but it seems like you cannot have one digit numbers in the original sequence. For example, for test case 2, if you output "10 00" (which would translate to sequence 01 00, which ARE two consecutive numbers), you'll get wrong answer. Moral of the story, start checking for numbers from 10. import java.util.Scanner; public class ex2031 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==1){ System.out.println("11"); }else{ if(n==2){ System.out.println("11"+" "+"01"); }else{ if(n==3){ System.out.println("001"+" "+"66"+" "+"86"); }else{ if(n==4){ System.out.println("16"+" "+"06"+" "+"68"+" "+"88"); }else{ System.out.println("Glupenky Pierre"); } } } } } } Он не может использовать трёхзначные числа int n = in.nextInt(); int l = 0; if (n > 24) { out.print("Glupenky Pierre"); } else { for (int i = 1; i <= n; i++) { if (i / 5 == 0) l = 0; if (i / 5 == 1) l = 1; if (i / 5 == 2) l = 8; if (i / 5 == 3) l = 6; if (i / 5 == 4) l = 9; if (i % 5 == 0) l = l * 10; if (i % 5 == 1) l = l * 10 + 1; if (i % 5 == 2) l = l * 10 + 8; if (i % 5 == 3) l = l * 10 + 6; if (i % 5 == 4) l = l * 10 + 9; if (l/10==0) out.print("0"); out.print(l); out.print(" "); } } Edited by author 07.11.2016 22:26 Edited by author 07.11.2016 22:27 Edited by author 27.01.2015 16:39 import java.util.Scanner; /** * Created by Coder on 23.01.2015. */ public class OverturnedNumbers2031_ { public static void main(String[] args) { Scanner x = new Scanner(System.in); int n = x.nextInt(); if (n == 1) { System.out.println("01"); } else if (n == 2) { System.out.println("11 01"); } else if (n == 4) { System.out.println("16 06 68 88"); } else { System.out.println("Glupenky Pierre"); } } } You did not write a case of n=3.. Thanks a lot of.I got it. n = 3 -> "16 06 68"; Edited by author 14.02.2015 22:43 The best solution ever xD Why only 4 cases ?? Not all these are ok ?? "11", "01", "08", "06", "09", "10", "18", "16", "19", "80", "81", "86", "88", "89", "60", "68", "61", "66", "69", "90", "91", "98", "96", "99" only 4 cases Edited by author 05.12.2014 19:38 Edited by author 05.12.2014 19:39 |
|
|