4 строки 274 байта кто короче? Unfortunately, I can't write the Python solution due to the rules, but it exists! Try to find it! var a: array[1..2000] of string; i: integer; begin for i := 1 to 2000 do begin if (i >= 1) and (i < 5) then a[i] := 'few'; if (i >= 5) and (i < 10) then a[i] := 'several'; if (i >= 10) and (i < 20) then a[i] := 'pack'; if (i >= 20) and (i < 50) then a[i] := 'lots'; if (i >= 50) and (i < 100) then a[i] := 'horde'; if (i >= 100) and (i < 250) then a[i] := 'throng'; if (i >= 250) and (i < 500) then a[i] := 'swarm'; if (i >= 500) and (i < 1000) then a[i] := 'zounds'; if i >= 1000 then a[i] := 'legion'; end;
readln(i); writeln(a[i]);
end. using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp9 { class Program { static void Main(string[] args) { int a1; a1 = Convert.ToInt32(Console.ReadLine()); if (a1 >= 1 && a1 <= 2000) if (a1 >= 1 && a1 <= 4) { Console.WriteLine("few"); } if (a1 >= 5 && a1 <= 9) { Console.WriteLine("several"); } if (a1 >= 10 && a1 <= 19) { Console.WriteLine("pack"); } if (a1 >= 20 && a1 <= 49) { Console.WriteLine("lots"); } if (a1 >= 50 && a1 <= 99) { Console.WriteLine("horde"); } if (a1 >= 100 && a1 <= 249) { Console.WriteLine("thorg"); } if (a1 >= 250 && a1 <= 499) { Console.WriteLine("swarm"); } if (a1 >= 500 && a1 <= 999) { Console.WriteLine("zounds"); } if (a1 >= 1000) { Console.WriteLine("legion"); } return; } } } Python 3.6 a=int(input()) if a<=4 and a>=1: print("few") if a<=9 and A>=5: print("several") if a<=19 and a>=10: print("pack") if a<=49 and a>=20: print("lots") if a<=99 and a>=50: print("horde") if a<=249 and a>=100: print("throng") if a<=499 and a>=250: print("swarm") if a<=999 and a>=500: print("zounds") if a>=1000: print("legion") Попробуй другие отступы num_monst = int (input ("Write number of monster")) if 1 <= num_monst <= 4: print("few") elif 5 <= num_monst <= 9: print("several") elif 10 <= num_monst <= 19 : print("lots")
elif 20 <= num_monst <= 49 : print("horde") elif 50 <= num_monst <= 99 : print("throng") elif 100 <= num_monst <= 249 : print("swarm") elif 250 <= num_monst <= 999 : print("zounds") elif num_monst >= 1000 : print("legion") Edited by author 13.01.2020 19:23 Edited by author 13.01.2020 19:23 Write code that way: if(n>=1000) puts("legion"); else if (n>=500) puts("zounds"); else if (n>=250) puts("swarm"); else if (n>=100) puts("throng"); else if (n>=50) puts("horde"); else if (n>=20) puts("lots"); else if (n>=10) puts("pack"); else if (n>=5) puts("several"); else puts("few"); Я не понимаю, что здесь не правильного??? #include <iostream> #include <string> using namespace std; int main() { string name[] = { "few", "several", "pack", "lots", "horde", "throng", "swarm", "zounds", "legion" }; int input; cin >> input; if (input >=1 && input <= 4) cout << name[0]; if (input > 4 && input <= 9) cout << name[1]; if (input > 9 && input <= 19) cout << name[2]; if (input > 19 && input <= 49) cout << name[3]; if (input > 49 && input <= 99) cout << name[4]; if (input > 99 && input <= 249) cout << name[5]; if (input > 249 && input <= 499) cout << name[6]; if (input > 499 && input <= 999) cout << name[7]; if (input > 1000) cout << name[8]; return 0; } Подскажите, пожалуйста! у тебя случай n=1000 никуда не включен. you forgot n=1000 case. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { int x; x = Convert.ToInt32 (Console.ReadLine()); if ((x > 1 & x <= 4) { Console.WriteLine("few"); } if (x > 5 & x<= 9) { Console.WriteLine("several"); } if (x > 10 & x <= 19) { Console.WriteLine("pack"); } if (x > 20 & x <= 49) { Console.WriteLine("lots"); } if (x > 50 & x <= 99) { Console.WriteLine("horde"); } if (x > 100 & x <= 249) { Console.WriteLine("throng"); } if (x > 250 & x <= 499) { Console.WriteLine("swarm"); } if (x > 500 & x <= 499) { Console.WriteLine("zounds"); } if (x > 1000) { Console.WriteLine("legion"); } } } } Да что тут не так? Edited by author 18.04.2018 23:36 Edited by author 18.04.2018 23:37 У вас везде > вместо >=. Ну и тут отдельная ошибка if (x > 500 & x <= 499) Have solved this task in Python many years ago. How test my code on Python and have Accept This code on Ruby have WA on test №3 The problem fixed Stay tuned and inform us as quick as possible. Только начал изучать С++. Решаю задачки для новичков. Что не так здесь? #include <iostream> #include <conio.h> using namespace std; int main() { int A; cout << "How many?"; cin >> A; if(A < 1 || A > 2000) { cout << "wrong input!"; }else { if(A <= 4) cout << "few"; else if(A <= 9) cout << "several"; else if(A <= 19) cout << "pack"; else if(A <= 49) cout << "lots"; else if(A <= 99) cout << "horde"; else if(A <= 249) cout << "throng"; else if(A <= 499) cout << "swarm"; else if(A <= 999) cout << "zounds"; else cout << "legion";} return 0; } компилировал на Visual studio 2012 - все работает. почему тут не принимает? don`t write How many it is wrong : and not "||" you should "&&" it is true good luck #include <iostream> using namespace std; int main() { int a; cin >> a; if (a >= 1 and a <= 4){ cout << "few"; if (a >= 5 and a <= 9){ cout << "several"; if (a >= 10 and a <= 19){ cout << "pack"; if (a >= 20 and a <= 49){ cout << "lots"; if (a >= 50 and a <= 99){ cout << "horde"; if (a >= 100 and a <= 249){ cout << "throng"; if (a >= 250 and a <= 499){ cout << " swarm"; if (a >= 500 and a <= 999){ cout << " zounds"; if (a > 1000){ cout << " legion"; } } #include <bits/stdc++.h> using namespace std; int main() {int x; vector <string> myvector (2001); fill (myvector.begin(),myvector.begin()+5,"few"); fill (myvector.begin()+6,myvector.begin()+10,"several"); fill (myvector.begin()+11,myvector.begin()+20,"pack"); fill (myvector.begin()+21,myvector.begin()+50,"lots"); fill (myvector.begin()+51,myvector.begin()+100,"horde"); fill (myvector.begin()+101,myvector.begin()+250,"throng"); fill (myvector.begin()+251,myvector.begin()+500,"swarm"); fill (myvector.begin()+501,myvector.begin()+1000,"zounds"); fill (myvector.begin()+1001,myvector.end(),"legion"); cin>>x; cout<<myvector[x]; return 0; } correct solution: #include <bits/stdc++.h> using namespace std; int main() {int x; vector <string> myvector (2001); fill (myvector.begin(),myvector.begin()+5,"few"); fill (myvector.begin()+5,myvector.begin()+10,"several"); fill (myvector.begin()+10,myvector.begin()+20,"pack"); fill (myvector.begin()+20,myvector.begin()+50,"lots"); fill (myvector.begin()+50,myvector.begin()+100,"horde"); fill (myvector.begin()+100,myvector.begin()+250,"throng"); fill (myvector.begin()+250,myvector.begin()+500,"swarm"); fill (myvector.begin()+500,myvector.begin()+1000,"zounds"); fill (myvector.begin()+1000,myvector.end(),"legion"); cin>>x; cout<<myvector[x]<<endl;; return 0; } Edited by author 30.09.2017 07:20 На руби вообще не имеет смысла что-то решать? Вы правы, думал несколько значений Why "wrong answer"? a=input() if 0<a<5: print('few') elif 4<a<10: print("sveral") elif 9<a<20: print("pack") elif 19<a<50: print("lots") elif 49<a<100: print('horde') elif 99<a<250: print('throng') elif 249<a<500: print("swarm") elif 499<a<1000: print("zounds") elif 1000<a: print ('legion') var n: integer; begin readln(n); if (n>=1) and (n<=4) then writeln('few'); if (n>=5) and (n<=9) then writeln('several'); if (n>=10) and (n<=19) then writeln('pack'); if (n>=20) and (n<=49) then writeln('lots'); if (n>=50) and (n<=99) then writeln('horde'); if (n>=100) and (n<=249) then writeln('throng'); if (n>=250) and (n<=499) then writeln('swarm'); if (n>=500) and (n<=999) then writeln('zounds'); if n>=1000 then writeln('legion'); end. will be better with CASE OF IMHO, using CASE OF operator, You'll get more esthetic look, no more. And insignificant advantage in performance. IlushaMax, could you check message year and don't answer if message is 2 (or more) years old? Thanks in advance. var n:integer; begin writeln(n); readln(n); case n of 1..4:begin writeln('few'); end; 5..9: begin writeln('several'); end; 10..19: begin writeln('pack'); end; 20..49: begin writeln('lots'); end; 50..99: begin writeln('horde'); end; 100..249: begin writeln('throng'); end; 250..499: begin writeln('swarm'); end; 500..999: begin writeln('zounds'); end; 1000..2000:begin writeln('legion'); end; end; end. Edited by author 24.11.2015 23:33 #include <stdio.h> #include<math.h> int main(){ int a=1; while ( a!= 0){ scanf("%d",&a); if (a>=1) if (a<=4) printf("few\n"); if (a>=5) if (a<=9) printf("several\n"); if (a>=10) if (a<=19) printf("pack\n"); if (a>=20) if (a<=49) printf("lots\n"); if (a>=50) if (a<=99) printf("horde\n"); if (a>=100) if (a<=249) printf("throng\n"); if (a>=250) if (a<=499) printf("swarm\n"); if (a>=500) if (a<=999) printf("zounds\n"); if (a>=1000) printf("legion\n"); } return 0; } Edited by author 02.07.2015 03:53 #include <iostream> using namespace std; int main() { int N; cin >> N; if(1 <= N && N <= 4) cout << "few"; if(5 <= N && N <= 9) cout << "several"; if(10 <= N && N <= 19) cout << "pack"; if(20 <= N && N <= 49) cout << "lots"; if(50 <= N && N <= 99) cout << "orde"; if(100 <= N && N <= 249) cout << "throng"; if(250 <= N && N <= 499) cout << "swarm"; if(500 <= N && N <= 999) cout << "zounds"; if(1000 <= N && N <= 2000) cout << "legion";
return 0; } Edited by author 02.04.2015 12:07 cout << "orde"; wrong cout << "horde"; ac |
|