├── Kattis ├── A Rational Sequence (Take 3) │ └── Main2.java ├── A Rational Sequence 2 │ └── Mine.java ├── ABC │ └── ABC.java ├── ARealChallenge │ └── ARealChallenge.java ├── Adding Words │ └── Main2.py ├── Bank queue │ └── Main24.java ├── Bijele │ └── Bijele.java ├── Breaking Bad │ └── Main.java ├── Build Dependencies │ └── Main4.java ├── Button Bashing │ └── Main4.java ├── Cantor │ └── Main.java ├── Coast length │ └── Main19.java ├── Counting Subsequences (Hard) │ └── main.cpp ├── Deduplicating files │ └── Main.py ├── FizzBuzz │ └── FizzBuzz.java ├── Flying saftey │ └── Main7.java ├── Fridge │ └── Fridge.cpp ├── Get Shorty │ └── main.cpp ├── Grandpa Bernie │ └── Main.py ├── Gregory the Grasshopper │ └── Main.java ├── Heritage-What Does It Mean │ ├── Main2.java │ └── Main8.py ├── Incognito │ └── Main6.py ├── Kastenlauf │ └── main.cpp ├── Lifting Walls │ └── main.cpp ├── Minimum Scalar Product │ └── Main23.java ├── Muzicary │ └── Main2.java ├── Numbers On a Tree │ └── Main3.java ├── Phone List │ └── Main7.java ├── Seven Wonders │ └── SevenWonders.cpp ├── Solving For Carrot │ └── main.java ├── Sylvester Construction │ └── main.cpp ├── Torn To Pieces │ └── Main4.java ├── TouchDown │ └── Main22.java ├── Virtual Friends │ └── main.cpp ├── Watering grass │ └── main.cpp ├── apaxiaaans │ └── Main.java ├── bachetsgame │ └── Main.java ├── gitKeeps ├── growlinggears │ └── Main.java ├── howmanydigits │ └── Main.java ├── minspantree │ └── main.cpp └── union find │ └── main.cpp ├── LICENSE ├── README.md ├── uva ├── 100 - The 3n + 1 problem │ └── Main.java ├── 10107 What is the Median │ └── Main1.py ├── 10189 - Minesweeper │ └── Main.java ├── 11057 Exact Sum │ └── main.cpp ├── 146 ID Codes │ └── main.cpp ├── 489 - Hangman Judge │ └── Main.java ├── 893Y3K Problem │ └── Main.java ├── Back to Intermediate Math │ └── main.cpp ├── Coin collector │ └── Main2.java ├── Digit Counting │ └── main.cpp ├── Freckles uva 10034 │ └── main.cpp ├── Numbering Roads │ └── main.cpp ├── Ordering tasks 10305 │ └── Main2.java ├── Scarecrow │ └── Main2.java ├── UVa 10125 - Sumsets │ └── Sumsets.java ├── UVa 10443 - Rock, Scissors, Paper │ └── Main.java ├── UVa 10656 - Maximum Sum (II) │ └── Main2.java ├── UVa 10718 - Bit Mask │ └── main.cpp ├── Watering grass │ └── main.cpp ├── Waterland uva 11655 │ └── Main4.java ├── gitKeep └── uva 1193 Radar installation │ └── Main.java └── پاسخ سوالات کوئرا ├── Bank Card Verifier └── answer.cpp ├── Cake └── Test.java ├── Ceremony └── answer.cpp ├── Congestion Charging Zone └── answer.cpp ├── Gold Rush └── answer.cpp ├── ICPC └── answer.cpp ├── gitKeep ├── gitkeep2 ├── آخ جون طرف نیست! └── Test.java ├── آسمان شکر آباد └── Test.java ├── آقای خوش‌قلب └── Main.java ├── اتل متل توتوله └── answer.cpp ├── اداره مالیات └── answer.cpp ├── ارسال سنگین └── Test.java ├── استارت-آپ باکلاس └── solution.py ├── اسم ها ├── AMK-solution │ └── Main.java ├── Main.java └── answer.cpp ├── اسنپ در شکرستان └── Test2.java ├── اعداد اول ├── Main.java └── PrimeNumbers.py ├── ام تایی ها └── solution.py ├── ام سین └── Main.java ├── انرژی خور └── answer.cpp ├── اوقات فراغت └── Test4.java ├── اول‌بینی ├── AvalBini.py └── Main.java ├── باب و کلید تلویزیون └── Test.java ├── بارکد └── answer.py ├── بازرگانی سوکرات و پسران └── Main.java ├── بازگشت از بوستان └── Main.java ├── بازی کلمه ها └── practice.py ├── باقر حال نداره ولی پول داره └── Main.java ├── باقر خسته ست ولی بی فرهنگ نه └── Test.java ├── باقر مخالف است ├── Test.java └── Test4.java ├── بالین └── calculator.py ├── بتایپ └── Test.java ├── بدخواه پویان └── Main.java ├── بلندگو └── Main.java ├── بمب بازی └── Main2.java ├── بهداشت و سلامت └── Test.java ├── تاریخ تولد └── Main.java ├── تایپیست بزرگ └── Main.java ├── تتریس └── answer.cpp ├── تخطی گری └── source.py ├── تخفیف جشنواره └── answer.cpp ├── تطابق رشته └── answer.cpp ├── تو چقدر اضافه وزن داری؟ ├── Main.java └── Main2.java ├── توان دو ├── Main.java └── power2.py ├── تولد تاریخی └── answer.cpp ├── تک رقمی ├── Test.java └── practice.py ├── تکسلنگ └── main.java ├── تی شرت برنده └── Main.java ├── تیله های توی کیسه └── answer.cpp ├── تیم کشی └── Test.java ├── ثبت نام └── source.py ├── جاده کشی ├── Test.java └── practice.py ├── جاستیفای └── answer.cpp ├── جایگشت‌ها └── Main.java ├── جدول ضرب گنده └── Main.java ├── جدی └── answer.cpp ├── جمع اعداد └── Main.java ├── جنایت └── answer.cpp ├── حرکت روی ظروف └── Test.java ├── خب باقر سرما خورده └── Test.java ├── خر در چمن فراوونه!! └── Test.java ├── خریدار ناشی └── Main.java ├── خواب پوپک └── Test.java ├── خوش آمد └── khoshAmad.py ├── خیلی قهوه ای یا باج یا خوش‌خوار └── answer.cpp ├── دایره عجیب ├── Main.java └── main.cpp ├── در آزمایشگاه └── answer.cpp ├── دزد پرنده └── answer.cpp ├── دسته به دسته └── answer.cpp ├── دنباله فیبوناچی برگشتی └── Main.java ├── دو نقطه خط └── Main.java ├── دوربین مداربسته └── Test.java ├── دیوار مهربانی └── answer.cpp ├── رشته فیبوناچی └── Main.java ├── رشته مورد علاقه └── answer.cpp ├── رشته های وارواژه └── answer.cpp ├── رمز └── Test.java ├── روز آزادی بیان در برره └── Main.java ├── رژیم سخت ├── Main.java ├── Main2.java ├── main.cpp └── practice.py ├── رییس و کارخانه شکلات‌سازی ├── Main5.java └── answer.py ├── زرد └── Main.java ├── زوج سرمایه دار └── Test.java ├── زیررشته مشترک └── temp.py ├── ساده تر └── Main.java ├── ساعت کار └── answer.py ├── سریال ├── answer.cpp └── temp.py ├── سطح اعتیاد └── main.cpp ├── سطح مکعب └── answer.cpp ├── سلام سلام خداحافظ └── Main.java ├── سوال اول └── Main.java ├── سوراخ موش └── SorakhMoosh.py ├── سپیده └── Test.java ├── سیکل گرفتن در برره └── Test.java ├── سیگماگیر └── Main.java ├── شارژ موبایل └── Main.java ├── شطرنج حرفه‌ای ├── Test.java └── main.cpp ├── شظرنج میوه ای └── solution.py ├── صبا و سوال ساده └── Main.txt ├── صدگان خسته └── Main2.java ├── عدد خود مغلوب └── Khod Maqlob.py ├── قرارمون یادت نره └── answer.py ├── قطار کامیابی └── Main8.java ├── قناد ناشی └── answer.cpp ├── لکنت ├── Test.java └── answer.cpp ├── ماشین متنی └── answer.cpp ├── ماکزیمم عدد ├── Main.java └── maximum.py ├── مثلث خیام ├── MosalasKhayam.py └── Pascal.java ├── مثلث ها └── answer.cpp ├── مجید و ماژیک هاش └── Test2.java ├── مجید، میلاد، رشته‌سازی └── Main.java ├── مربّاها و قفسه‌بندی └── Main.java ├── مرتب سازی رشته ها └── temp.py ├── مسئله ی آب └── Test.java ├── مسابقه آسان └── مسابقه‌ی آسان.py ├── مساحت └── solution.py ├── مساله هالت └── answer.py ├── مستطیل بد └── Test4.java ├── مستطیل کادویی └── answer.cpp ├── مشق امشب باقر ├── Main.java ├── Triangle.py └── practice.py ├── مصاحبه با وزیران └── answer.cpp ├── معادله های پیچیده └── answer.py ├── مقایسه گر └── solution.py ├── مقسوم علیه های دردسرساز └── Main.java ├── مُجَزا └── solution.py ├── نرمش جدول └── Main3.java ├── نظریه ریسمان └── Risman.py ├── نعلم کو؟! └── answer.cpp ├── نمک زندگی └── Main.java ├── نیمبو-آمار مسابقه └── Main.java ├── نیمبو-دومینوها └── Main.java ├── نیمبو-صفا └── Main.java ├── همایش زندگی بهتر └── Test.java ├── هندونه خوری ├── Main.java └── Main2.java ├── هوهوچیچی └── answer.cpp ├── هیچ‌وقت مغرور نشو! └── Main2.java ├── وزیر و تقسیم زمین └── main.cpp ├── وسط صندلی عقب └── Test.java ├── پاکسازی └── Test.java ├── پیدایِش └── peydayesh.py ├── چارپک └── answer.cpp ├── چاپ برعکس ├── AMK-solution │ └── Main.java └── Main.java ├── چاپ لوزی └── chapeLoozi.py ├── چاپ مربع ├── Main.java └── morabaa.py ├── چند روزته؟ └── Main.java ├── چی سون ├── Main.java └── answer.py ├── چیدمان └── Test.java ├── چیهمونی └── answer.cpp ├── کاغذ کادو چهارضلعی └── answer.cpp ├── کاف کیک └── Test.java ├── کامل بودن یا نبودن ├── Main.cpp ├── Main.java └── completeOrNot.py ├── کدتخفیف └── Test3.java ├── کشمش در پارک └── answer.cpp ├── کلاس تقویتی └── answer.cpp ├── کلید چراغ ├── KilidCheraq.py └── Main.java ├── کمک به کاپی ├── AMK-solution │ └── Main.java └── Main.java ├── کوچک بزرگ └── answer.cpp ├── کوین و قدرت شالاپ └── Main.java ├── گراف افکار └── answer.cpp ├── گردو شکستم └── Test.java ├── گزارش کار └── GozaresheKar.py ├── یافتن عدد اول └── Main.java ├── یخدارچی ├── AMK-solution │ └── Main.java ├── Main.java └── practice.py ├── یک ساعت └── Test.java └── یک سوال ساده ├── Main.java └── practice.py /Kattis/A Rational Sequence (Take 3)/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main2 { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | int P = scanner.nextInt(); 7 | for (int i = 0; i < P; i++) { 8 | int j = scanner.nextInt(); 9 | long n = scanner.nextLong(); 10 | System.out.print(j+" "); 11 | getN(n); 12 | } 13 | } 14 | 15 | private static void getN(long i) { 16 | String str = Long.toBinaryString(i); 17 | int p = 1,q = 1; 18 | for (int j = 1; j < str.length(); j++) { 19 | if (str.charAt(j) == '0'){ 20 | //go left: 21 | q = p + q; 22 | }else{ 23 | //go right: 24 | p = p + q; 25 | } 26 | } 27 | System.out.println(p+"/"+q); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Kattis/A Rational Sequence 2/Mine.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class Mine { 5 | private static String ans = ""; 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | int P = scanner.nextInt(); 10 | for (int i = 0; i < P; i++) { 11 | scanner.nextInt(); 12 | String s = scanner.next(); 13 | int p = Integer.parseInt(s.split("/")[0]); 14 | int q = Integer.parseInt(s.split("/")[1]); 15 | System.out.print(i + 1 + " "); 16 | Calc(p, q, 1); 17 | ans = "1" + ans; 18 | System.out.println(new BigInteger(ans, 2).longValue()); 19 | ans = ""; 20 | } 21 | } 22 | 23 | private static int Calc(int p, int q, int i) { 24 | if (p == 1 && q == 1) { 25 | return i; 26 | } 27 | if (p > q) { 28 | // right child: 29 | ans = "1" + ans; 30 | return Calc(p - q, q, i + 1); 31 | } else { 32 | // left child: 33 | ans = "0" + ans; 34 | return Calc(p, q - p, i + 1); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Kattis/ABC/ABC.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class ABC { 5 | 6 | public static void main ( String[] args ) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String[] data = scanner.nextLine().split( " " ); 10 | String letters = scanner.nextLine(); 11 | 12 | int[] numbers = new int[data.length]; 13 | for ( int i = 0; i < 3; i++ ) { 14 | numbers[i] = Integer.parseInt( data[i] ); 15 | } 16 | 17 | Arrays.sort( numbers ); 18 | for ( int i = 0; i < letters.length(); i++ ) { 19 | if ( letters.charAt( i ) == 'A' ) 20 | System.out.print( numbers[0] + " " ); 21 | else if ( letters.charAt( i ) == 'B' ) 22 | System.out.print( numbers[1] + " "); 23 | else if ( letters.charAt( i ) == 'C' ) 24 | System.out.print( numbers[2] + " " ); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Kattis/ARealChallenge/ARealChallenge.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ARealChallenge { 4 | 5 | public static void main( String[] args ) { 6 | Scanner scanner = new Scanner(System.in); 7 | long area = Long.parseLong(scanner.next()); 8 | System.out.println(Math.sqrt(area) * 4); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Kattis/Adding Words/Main2.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | dic = {} 3 | for line in stdin: 4 | command = line.split(" ")[0] 5 | if command == 'def': 6 | dic[line.split(" ")[1]] = int(line.split(" ")[2]) 7 | elif command == 'calc': 8 | flag = True 9 | arr = line.split(" ") 10 | first_word = arr[0] 11 | answer = line[len(first_word) + 1: len(line) - 1] 12 | ans = 0 13 | operator = '+' 14 | for i in range(1,len(arr)): 15 | if i % 2 != 0: 16 | if arr[i] not in dic and arr[i] != '=': 17 | flag = False 18 | else: 19 | if operator == '+': 20 | ans += dic[arr[i]] 21 | else: 22 | ans -= dic[arr[i]] 23 | else: 24 | operator = arr[i] 25 | if not flag: 26 | print("%s %s" %(answer,'unknown')) 27 | else: 28 | FF = False 29 | for key,value in dic.items(): 30 | if value == ans: 31 | print("%s %s" %(answer, key)) 32 | FF = True 33 | break 34 | if not FF: 35 | print("%s %s" %(answer,'unknown')) 36 | else: 37 | dic.clear() -------------------------------------------------------------------------------- /Kattis/Bank queue/Main24.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 7/27/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main24 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int n = scanner.nextInt(); 12 | int T = scanner.nextInt(); 13 | ArrayListarrayList = new ArrayList<>(); 14 | for (int i = 0; i < n; i++) { 15 | int x = scanner.nextInt(); 16 | int y = scanner.nextInt(); 17 | Member member = new Member(); 18 | member.money = x; 19 | member.time = y; 20 | arrayList.add(member); 21 | } 22 | arrayList.sort(Collections.reverseOrder()); 23 | int amount = 0; 24 | for (int i = T - 1; i > -1; i--) { 25 | for (int j = 0; j < arrayList.size(); j++) { 26 | if (arrayList.get(j).time >= i){ 27 | amount += arrayList.get(j).money; 28 | arrayList.remove(j); 29 | break; 30 | } 31 | } 32 | } 33 | System.out.println(amount); 34 | } 35 | 36 | static class Member implements Comparable { 37 | int time, money; 38 | 39 | @Override 40 | public String toString() { 41 | return "Member{" + 42 | "time=" + time + 43 | ", money=" + money + 44 | '}'; 45 | } 46 | 47 | @Override 48 | public int compareTo(Member member) { 49 | return this.money > member.money ? 1 : -1; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Kattis/Bijele/Bijele.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Bijele { 4 | 5 | public static void main( String[] args ) { 6 | Scanner scanner = new Scanner( System.in ); 7 | 8 | int[] output = new int[]{ 1, 1, 2, 2, 2, 8 }; //numbers of kings, queens, rooks, bishops, knights and pawn 9 | String[] data = scanner.nextLine().split( " " ); 10 | 11 | for ( int i = 0; i < output.length; i++ ) { 12 | output[i] -= Integer.parseInt( data[i] ); 13 | System.out.print(output[i] + " "); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Kattis/Button Bashing/Main4.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 8/6/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main4 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int q = scanner.nextInt(); 12 | for (int i = 0; i < q; i++) { 13 | int n = scanner.nextInt(); 14 | int t = scanner.nextInt(); 15 | ArrayList arrayList = new ArrayList<>(); 16 | for (int j = 0; j < n; j++) { 17 | arrayList.add(scanner.nextInt()); 18 | } 19 | int dist[] = new int[3605]; 20 | Arrays.fill(dist, 3601); 21 | Queue queue = new LinkedList<>(); 22 | queue.add(0); 23 | dist[0] = 0; 24 | while (!queue.isEmpty()){ 25 | int curr = queue.poll(); 26 | for (int j = 0; j < arrayList.size(); j++) { 27 | int node = curr + arrayList.get(j); 28 | node = Math.max(0, node); 29 | node = Math.min(node, 3600); 30 | if (dist[node] > dist[curr] + 1){ 31 | dist[node] = dist[curr] + 1; 32 | queue.add(node); 33 | } 34 | } 35 | } 36 | int min = 0; 37 | int time = 3601; 38 | for (int j = t; j < dist.length; j++) { 39 | if (dist[j] < time){ 40 | min = j - t; 41 | time = dist[j]; 42 | break; 43 | } 44 | } 45 | System.out.println(time + " " +min); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Kattis/Cantor/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 8/2/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | while (true) { 12 | String command = scanner.nextLine().split(" ")[0]; 13 | if (command.equals("END")) 14 | break; 15 | Double x = Double.parseDouble(command); 16 | if (x == 0 || x == 1) { 17 | System.out.println("MEMBER"); 18 | continue; 19 | } 20 | x = x - x.intValue(); 21 | x = x * 1000000; 22 | if (Calc(x)) { 23 | System.out.println("MEMBER"); 24 | } else { 25 | System.out.println("NON-MEMBER"); 26 | } 27 | } 28 | } 29 | 30 | private static boolean Calc(Double x) { 31 | int y = x.intValue(); 32 | HashSet hashSet = new HashSet<>(); 33 | while (!hashSet.contains(y)) { 34 | hashSet.add(y); 35 | y *= 3; 36 | if (y / 1000000 == 1) { 37 | return false; 38 | } 39 | y = y % 1000000; 40 | } 41 | return true; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Kattis/Deduplicating files/Main.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | while n != 0: 3 | dic = {} 4 | ss = set() 5 | for i in range(0, n): 6 | line = input() 7 | ss.add(line) 8 | ans = ord(line[0]) 9 | for j in range(1, len(line)): 10 | ans ^= ord(line[j]) 11 | if ans in dic: 12 | dic[ans][0] += 1 13 | if line not in dic[ans][1]: 14 | dic[ans][1][line] = 1 15 | else: 16 | dic[ans][1][line] += 1 17 | else: 18 | dic[ans] = [1, {line: 1}] 19 | collisions = 0 20 | for v in dic.values(): 21 | if v[0] > 1: 22 | for v2 in v[1].values(): 23 | collisions += (v[0] - v2) * v2 24 | 25 | print(str(len(ss)) + " " + str(collisions // 2)) 26 | n = int(input()) 27 | -------------------------------------------------------------------------------- /Kattis/FizzBuzz/FizzBuzz.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class FizzBuzz { 4 | 5 | public static void main( String[] args ) { 6 | Scanner scanner = new Scanner( System.in ); 7 | int inputX = scanner.nextInt(); 8 | int inputY = scanner.nextInt(); 9 | int inputN = scanner.nextInt(); 10 | 11 | for ( int i = 1; i < inputN + 1; i++ ) { 12 | boolean isFizz = i % inputX == 0; 13 | boolean isBuzz = i % inputY == 0; 14 | 15 | System.out.println( isFizz && isBuzz ? "FizzBuzz" : isFizz ? "Fizz" : isBuzz ? "Buzz" : i + "" ); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Kattis/Flying saftey/Main7.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main7 { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | int t = scanner.nextInt(); 7 | for (int i = 0; i < t; i++) { 8 | int n = scanner.nextInt(); 9 | int m = scanner.nextInt(); 10 | for (int j = 0; j < m; j++) { 11 | int a = scanner.nextInt(); 12 | int b = scanner.nextInt(); 13 | } 14 | System.out.println(n - 1); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Kattis/Fridge/Fridge.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | int n,x; 9 | 10 | int memo[10001]; 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | string input; 18 | cin>>input; 19 | int ch[1000]; 20 | for(int i = 0; i < input.size (); i++){ 21 | ch[input.at(i) - '0']++; 22 | } 23 | int k = 0; 24 | int candidate = 0; 25 | for(int j = 1; j < 10; j++){ 26 | ch[j]--; 27 | if(ch[j] < 0){ 28 | candidate = j; 29 | break; 30 | } 31 | if(j == 9){ 32 | k++; 33 | j = -1; 34 | } 35 | } 36 | int i = 0; 37 | if(candidate == 0){ 38 | cout<<1; 39 | i++; 40 | } 41 | for(; i < k; i++){ 42 | cout< 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 6 | typedef std::vector> vvi; 7 | typedef long long ll; 8 | int INF = INT32_MIN; 9 | using namespace std; 10 | 11 | void fast() { 12 | ios::sync_with_stdio(false); 13 | cin.tie(nullptr); 14 | cout.tie(nullptr); 15 | } 16 | 17 | struct Node{ 18 | int node; 19 | float cost; 20 | }; 21 | 22 | struct node_cmp { 23 | bool operator()(Node const& p1, Node const& p2) 24 | { 25 | return p1.cost < p2.cost; 26 | } 27 | }; 28 | 29 | int main() { 30 | int n, m; 31 | while (true) { 32 | cin >> n >> m; 33 | if (n == m && m == 0) 34 | break; 35 | priority_queue,node_cmp> priorityQueue; 36 | Node node0{}; 37 | node0.cost = 1.0; 38 | node0.node = 0; 39 | vector > > arr(n); 40 | for (int i = 0; i < m; ++i) { 41 | int x, y; 42 | float coefficient; 43 | cin>>x>>y>>coefficient; 44 | arr[x].push_back(make_pair(coefficient, y)); 45 | arr[y].push_back(make_pair(coefficient, x)); 46 | } 47 | vector vis(n, false); 48 | vector dis(n,0.0); 49 | dis[0] = 0.0; 50 | priorityQueue.push(node0); 51 | while(!priorityQueue.empty()){ 52 | Node curr = priorityQueue.top(); 53 | priorityQueue.pop(); 54 | vis[curr.node] = 1; 55 | for (auto i : arr[curr.node]) { 56 | if(i.second != 0 && vis[i.second] == 0){ 57 | float new_dis = curr.cost * i.first; 58 | if (new_dis > dis[i.second]) { 59 | Node xx{}; 60 | xx.node = i.second; xx.cost = new_dis; 61 | priorityQueue.push(xx); 62 | dis[i.second] = new_dis; 63 | } 64 | } 65 | } 66 | } 67 | printf("%.4f\n", dis[n - 1]); 68 | } 69 | return 0; 70 | } -------------------------------------------------------------------------------- /Kattis/Grandpa Bernie/Main.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | n = int(input()) 3 | dic = defaultdict(list) 4 | for i in range(0,n): 5 | line = input() 6 | dic[line.split(" ")[0]].append((int(line.split(" ")[1]))) 7 | for key in dic: 8 | dic[key] = list(sorted(dic[key])) 9 | q = int(input()) 10 | for i in range(0,q): 11 | line = input() 12 | name = line.split(" ")[0] 13 | time = int(line.split(" ")[1]) 14 | print(dic[name][time - 1]) -------------------------------------------------------------------------------- /Kattis/Heritage-What Does It Mean/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 7/30/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main2 { 9 | private static HashMap table = new HashMap<>(); 10 | private static HashMap memo = new HashMap<>(); 11 | private static ArrayList keys = new ArrayList<>(); 12 | 13 | public static void main(String[] args) { 14 | Scanner scanner = new Scanner(System.in); 15 | int N = scanner.nextInt(); 16 | String W = scanner.next(); 17 | for (int i = 0; i < N; i++) { 18 | String str = scanner.next(); 19 | int val = scanner.nextInt(); 20 | keys.add(str); 21 | table.put(str, val); 22 | } 23 | System.out.println(Calc(W)); 24 | } 25 | private static long Calc(String string){ 26 | if (memo.containsKey(string)) { 27 | return memo.get(string); 28 | } 29 | if (string.length() == 0){ 30 | return 0; 31 | } 32 | long mark = table.containsKey(string) ? table.get(string) : 0; 33 | int INF = 1000000007; 34 | for (String key : keys) { 35 | if (string.startsWith(key)) { 36 | mark += (table.get(key) * Calc(string.substring(key.length(), string.length())) % INF); 37 | } 38 | } 39 | memo.put(string,mark % INF); 40 | return mark % INF; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Kattis/Heritage-What Does It Mean/Main8.py: -------------------------------------------------------------------------------- 1 | _memo = {} 2 | BIGPRIME = 1000000007 3 | 4 | 5 | def count_meanings(d, word): 6 | if word in _memo: 7 | return _memo[word] 8 | meaning = d[word] if word in d else 0 9 | for i in range(1, len(word)): 10 | f = word[:i] 11 | l = word[i:] 12 | if f in d: 13 | meaning += d[f] * count_meanings(d, l) 14 | _memo[word] = meaning % BIGPRIME 15 | return meaning % BIGPRIME 16 | 17 | 18 | def main(): 19 | N, name = input().split() 20 | dictionary = {} 21 | for _ in range(int(N)): 22 | w, m = input().split() 23 | dictionary[w] = int(m) 24 | 25 | meanings = count_meanings(dictionary, name) 26 | print(meanings) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /Kattis/Incognito/Main6.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(0, t): 3 | n = int(input()) 4 | dic = {} 5 | for j in range(0, n): 6 | line = input() 7 | s1 = line.split(" ")[0] 8 | s2 = line.split(" ")[1] 9 | if s2 in dic: 10 | dic[s2] += 1 11 | else: 12 | dic[s2] = 2 13 | ans = 1 14 | for k in dic: 15 | ans *= dic[k] 16 | print(ans - 1) 17 | -------------------------------------------------------------------------------- /Kattis/Minimum Scalar Product/Main23.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * Created by AMK on 7/27/2019. 7 | * Life is nice :) 8 | * Enjoy coding :D 9 | */ 10 | public class Main23 { 11 | public static void main(String[] args) { 12 | Scanner scanner = new Scanner(System.in); 13 | int T = scanner.nextInt(); 14 | for (int i = 0; i < T; i++) { 15 | int n = scanner.nextInt(); 16 | ArrayList arrayList = new ArrayList<>(); 17 | ArrayList arrayList1 = new ArrayList<>(); 18 | for (int j = 0; j < n; j++) { 19 | arrayList.add(scanner.nextLong()); 20 | } 21 | for (int j = 0; j < n; j++) { 22 | arrayList1.add(scanner.nextLong()); 23 | } 24 | Collections.sort(arrayList); 25 | Collections.sort(arrayList1,Collections.reverseOrder()); 26 | Long ans = 0L; 27 | for (int j = 0; j < n; j++) { 28 | ans += arrayList.get(j) * arrayList1.get(j); 29 | } 30 | System.out.println("Case #" + (i + 1) + ": " + ans); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Kattis/Numbers On a Tree/Main3.java: -------------------------------------------------------------------------------- 1 | import java.util.Collections; 2 | import java.util.Scanner; 3 | 4 | public class Main3 { 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | String line = scanner.nextLine(); 8 | int h = Integer.parseInt(line.split(" ")[0]); 9 | String instructions = ""; 10 | if (line.split(" ").length > 1) { 11 | instructions= line.split(" ")[1]; 12 | } 13 | long pivot = 1; 14 | for (int i = 0; i < instructions.length(); i++) { 15 | if (instructions.charAt(i) == 'L'){ 16 | pivot = 2*pivot; 17 | }else if (instructions.charAt(i) == 'R'){ 18 | pivot = 2*pivot + 1; 19 | } 20 | } 21 | long ans = (((long)Math.pow(2,h+1)) - pivot); 22 | System.out.print(ans); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis/Phone List/Main7.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 8/7/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main7 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int t = scanner.nextInt(); 12 | for (int i = 0; i < t; i++) { 13 | int n = scanner.nextInt(); 14 | HashSet hashSet = new HashSet<>(); 15 | int j; 16 | ArrayList arrayList = new ArrayList<>(); 17 | for (j = 0; j < n; j++) { 18 | String line = scanner.next(); 19 | arrayList.add(new Member(line)); 20 | } 21 | boolean flag = true; 22 | Collections.sort(arrayList); 23 | for (int k = 0; k < arrayList.size(); k++) { 24 | String line = arrayList.get(k).number; 25 | int o = 1; 26 | for (; flag && o <= line.length(); o++) { 27 | String x = line.substring(0, o); 28 | if (hashSet.contains(x)) { 29 | System.out.println("NO"); 30 | flag = false; 31 | break; 32 | } 33 | } 34 | if (!flag){ 35 | break; 36 | } 37 | hashSet.add(line); 38 | } 39 | if (flag) 40 | System.out.println("YES"); 41 | } 42 | } 43 | 44 | static class Member implements Comparable { 45 | String number; 46 | 47 | public Member(String number) { 48 | this.number = number; 49 | } 50 | 51 | @Override 52 | public int compareTo(Member member) { 53 | if (this.number.length() > member.number.length()) { 54 | return 1; 55 | } else if (this.number.length() == member.number.length()) { 56 | return 0; 57 | } else { 58 | return -1; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Kattis/Seven Wonders/SevenWonders.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | int n,x; 9 | 10 | int memo[10001]; 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | string input; 18 | cin>>input; 19 | int C = 0 , G = 0, T = 0; 20 | for(int i = 0; i < input.size (); i++){ 21 | if(input.at (i) == 'C'){ 22 | C++; 23 | }else if(input.at (i) == 'T'){ 24 | T++; 25 | }else{ 26 | G++; 27 | } 28 | } 29 | int ans = 0; 30 | if(C*G*T != 0){ 31 | ans += min(C,min(G,T))*7; 32 | } 33 | ans += C*C + G*G + T*T; 34 | cout<= 100){ 30 | System.out.println("Touchdown"); 31 | return; 32 | }else if (pos <= 0){ 33 | System.out.println("Safety"); 34 | return; 35 | } 36 | } 37 | System.out.println("Nothing"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Kattis/Watering grass/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = 999999; 10 | using namespace std; 11 | 12 | struct sprinkler{ 13 | double leftmost,rightmost,center; 14 | }; 15 | 16 | bool cmp(const sprinkler &i1, const sprinkler &i2) 17 | { 18 | return i1.leftmost < i2.leftmost; 19 | } 20 | 21 | 22 | int main(){ 23 | ios_base::sync_with_stdio(false); 24 | int n,l,w; 25 | while(cin>>n>>l>>w){ 26 | double x; 27 | double r; 28 | vector vec; 29 | for(int i = 0; i < n;i++){ 30 | sprinkler s; 31 | cin>>x>>r; 32 | if(r <= w/2){ 33 | continue; 34 | } 35 | s.leftmost = x - sqrt(r*r - (w * w)/4.0); 36 | s.rightmost = x + sqrt(r*r - (w * w)/4.0); 37 | s.center = x; 38 | vec.push_back (s); 39 | } 40 | sort(vec.begin (),vec.end (),cmp); 41 | int ans = 0; 42 | int i = 0; 43 | double prev = 0; 44 | for (; prev < l; ) { 45 | int flag = 0; 46 | double right = prev; 47 | 48 | for (; i < vec.size(); i++) { 49 | if (vec[i].leftmost > prev) { 50 | break; 51 | } 52 | if (vec[i].rightmost >= right) { 53 | right = vec[i].rightmost; 54 | flag = 1; 55 | } 56 | } 57 | 58 | if (flag == 0) { 59 | cout<<-1<= l) 66 | cout< workSimplified = new ArrayList<>(); 12 | workSimplified.add(String.valueOf(word.charAt(0))); 13 | int lastIndex = 0; 14 | 15 | for (int i = 1; i < word.length(); i++) { 16 | if (!(workSimplified.get(lastIndex).equals(String.valueOf(word.charAt(i))))) { 17 | workSimplified.add(String.valueOf(word.charAt(i))); 18 | lastIndex++; 19 | } 20 | } 21 | for (String s : workSimplified) { 22 | System.out.print(s); 23 | } 24 | System.out.println(""); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Kattis/bachetsgame/Main.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * Created by AMK on 8/11/2019. 7 | * Life is nice :) 8 | * Enjoy coding :D 9 | */ 10 | public class Main { 11 | private static BigInteger[] bigIntegers = new BigInteger[1000001]; 12 | 13 | public static void main(String[] args) { 14 | Scanner scanner = new Scanner(System.in); 15 | while (scanner.hasNext()){ 16 | String line[] = scanner.nextLine().split(" "); 17 | int n = Integer.parseInt(line[0]); 18 | int m = Integer.parseInt(line[1]); 19 | ArrayList arrayList = new ArrayList<>(); 20 | for (int i = 2; i < m + 2; i++) { 21 | arrayList.add(Integer.valueOf(line[i])); 22 | } 23 | int arr[] = new int[n + 1]; 24 | int j,i; 25 | //for P position: 26 | arr[0] = 0; 27 | for(i = 1; i <= n; ++i) { 28 | for(j = 0; j < m; ++j) { 29 | if (i - arrayList.get(j) >= 0) { 30 | if (arr[i - arrayList.get(j)] == 0) { 31 | //for N position: 32 | arr[i] = 1; 33 | break; 34 | } 35 | } 36 | } 37 | } 38 | if (arr[n] == 1){ 39 | System.out.println("Stan wins"); 40 | }else{ 41 | System.out.println("Ollie wins"); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Kattis/gitKeeps: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Kattis/growlinggears/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * Created by AMK on 8/11/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int t = scanner.nextInt(); 12 | for (int i = 0; i < t; i++) { 13 | int n = scanner.nextInt(); 14 | int id = 0; 15 | int max = Integer.MIN_VALUE; 16 | for (int j = 0; j < n; j++) { 17 | int a = scanner.nextInt(); 18 | int b = scanner.nextInt(); 19 | int c = scanner.nextInt(); 20 | int res = (b * b) /(4 * a) + c; 21 | if (res > max){ 22 | max = res; 23 | id = j + 1; 24 | } 25 | } 26 | System.out.println(id); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Kattis/howmanydigits/Main.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * Created by AMK on 8/11/2019. 7 | * Life is nice :) 8 | * Enjoy coding :D 9 | */ 10 | public class Main { 11 | private static BigInteger[] bigIntegers = new BigInteger[1000001]; 12 | 13 | public static void main(String[] args) { 14 | Scanner scanner = new Scanner(System.in); 15 | while (scanner.hasNext()) { 16 | int x = scanner.nextInt(); 17 | if (x == 0 || x == 1) { 18 | System.out.println(1); 19 | continue; 20 | } 21 | System.out.println((int) Math.ceil(Math.log10(2 * Math.PI * x) /2 + x * Math.log10(x / Math.E))); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Kattis/union find/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = -9999; 10 | using namespace std; 11 | 12 | void fast() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(NULL); cout.tie(NULL); 15 | } 16 | 17 | int *parent; 18 | int *ran; 19 | 20 | 21 | int find_root(int i){ 22 | while(parent[i] != i){ 23 | parent[i] = parent[parent[i]]; 24 | i = parent[i]; 25 | } 26 | return i; 27 | } 28 | 29 | void find(int node1, int node2){ 30 | int root1 = find_root (node1); 31 | int root2 = find_root (node2); 32 | if (root1 == root2) { 33 | cout<<"yes\n"; 34 | } else{ 35 | cout<<"no\n"; 36 | } 37 | 38 | } 39 | 40 | void merge(int node1, int node2){ 41 | int root1 = find_root (node1); 42 | int root2 = find_root (node2); 43 | if(root1 == root2) 44 | return; 45 | 46 | if(ran[root1]>n>>q; 63 | parent = new int[n]; 64 | ran = new int[n]; 65 | for(int i=0;i>command>>a>>b; 74 | if(command == '?'){ 75 | find(a,b); 76 | }else{ 77 | merge(a,b); 78 | } 79 | } 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Amir Mohammad Karimi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming problems 2 | Our answers to some programming problems, like ACM ICPC problems and others. (All problems are available on http://uva.onlinejudge.org or https://open.kattis.com) 3 | و پاسخ برخی سوالات کوئرا 4 | 5 | ## Getting Started 6 | - **Fork** this repository (Click the 'Fork' button, top right of this page) 7 | - **Clone** your forked copy of this repo down to your local machine: 8 | ``` 9 | git clone https://github.com//ProgrammingProblems.git 10 | ``` 11 | 12 | ## Contribution 13 | Contributions are more than welcome! Feel free to open a PR of your tested solutions :) 14 | 15 | If there is a previous answer to a question and you have a better (simpler, more readable, etc) answer, put the previous one in a dir named "AMK-solution" or "original-solution" in case the previous answer is not written by me. 16 | -------------------------------------------------------------------------------- /uva/100 - The 3n + 1 problem/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | while (scanner.hasNext()){ 8 | int a = scanner.nextInt(); 9 | int b = scanner.nextInt(); 10 | int x = Math.min(a,b); 11 | int y = Math.max(a,b); 12 | System.out.printf("%d %d %d\n",a,b,getMax(x,y)); 13 | } 14 | 15 | } 16 | 17 | private static int getMax(int a, int b) { 18 | int max = -1; 19 | for (int i = a; i <= b; i++) { 20 | int O_o = getIt(i,0); 21 | if (max < O_o){ 22 | max = O_o; 23 | } 24 | } 25 | return max; 26 | } 27 | 28 | private static int getIt(int i, int j) { 29 | if (i == 1){ 30 | return j + 1; 31 | } 32 | if (i % 2 == 0){ 33 | return getIt(i/2,j+1); 34 | }else{ 35 | return getIt(3*i+1,j+1); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /uva/10107 What is the Median/Main1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | arr = [] 4 | for line in sys.stdin: 5 | arr.append(int(line)) 6 | arr = sorted(arr) 7 | if len(arr) % 2 == 0: 8 | x = int((arr[int(len(arr) / 2)] + arr[int(len(arr) / 2) - 1]) / 2) 9 | else: 10 | x = arr[int(len(arr) / 2)] 11 | print(x) 12 | -------------------------------------------------------------------------------- /uva/11057 Exact Sum/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void getAns(vector v, int m){ 5 | for(int j = 0; j < v.size(); j++){ 6 | int i = v[j]; 7 | int x = m - i; 8 | if(binary_search(v.begin(),v.end(),x)){ 9 | cout<<"Peter should buy books whose prices are "<>N){ 18 | vector v; 19 | for(int i = 0; i < N; i++){ 20 | int x; 21 | cin>>x; 22 | v.push_back(x); 23 | } 24 | int m; 25 | cin>>m; 26 | getAns(v,m); 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /uva/146 ID Codes/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // ios::sync_with_stdio(false); 5 | string s; 6 | cin>>s; 7 | while(s != "#"){ 8 | int x = 0; 9 | string temp =s ; 10 | while(next_permutation(s.begin(),s.end())){ 11 | if(temp != s){ 12 | x++; 13 | cout<> s; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /uva/489 - Hangman Judge/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | int turn = scanner.nextInt(); 8 | int ___ = 0; 9 | while (turn != -1) { 10 | ___++; 11 | System.out.println("Round "+___); 12 | String original = scanner.next(); 13 | String guess = scanner.next(); 14 | int O_o = 0; 15 | int die = 0; 16 | HashSet hashSet_original = new HashSet<>(); 17 | for (int i = 0; i < original.length(); i++) { 18 | hashSet_original.add(original.charAt(i)); 19 | } 20 | ArrayList corrects = new ArrayList<>(); 21 | ArrayList wrongs = new ArrayList<>(); 22 | for (int i = 0; i < guess.length(); i++) { 23 | if (hashSet_original.size() == 0) { 24 | break; 25 | } 26 | if (hashSet_original.contains(guess.charAt(i))) { 27 | hashSet_original.remove(guess.charAt(i)); 28 | corrects.add(guess.charAt(i)); 29 | } else if (!corrects.contains(guess.charAt(i)) && !wrongs.contains(guess.charAt(i))) { 30 | wrongs.add(guess.charAt(i)); 31 | die++; 32 | } 33 | if (die == 7) { 34 | System.out.println("You lose."); 35 | O_o = -1; 36 | break; 37 | } 38 | } 39 | if (hashSet_original.size() == 0) { 40 | System.out.println("You win."); 41 | }else if (O_o != -1) { 42 | System.out.println("You chickened out."); 43 | } 44 | turn = scanner.nextInt(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /uva/893Y3K Problem/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Calendar; 2 | import java.util.GregorianCalendar; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | while (true) { 9 | int n = scanner.nextInt(); 10 | int day = scanner.nextInt(); 11 | int month = scanner.nextInt(); 12 | int year = scanner.nextInt(); 13 | if (year + n + day + month == 0){ 14 | break; 15 | } 16 | GregorianCalendar gregorianCalendar = new GregorianCalendar(year, month - 1, day); 17 | gregorianCalendar.add(Calendar.DAY_OF_YEAR, n); 18 | System.out.println(gregorianCalendar.get(Calendar.DAY_OF_MONTH) + " " + 19 | (gregorianCalendar.get(Calendar.MONTH) + 1) + " " + gregorianCalendar.get(Calendar.YEAR)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /uva/Back to Intermediate Math/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = INT32_MIN; 10 | using namespace std; 11 | 12 | void fast() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(NULL); cout.tie(NULL); 15 | } 16 | 17 | 18 | int main() { 19 | // fast(); 20 | long q; 21 | cin>>q; 22 | int t = 1; 23 | while(q--){ 24 | float d,u,v; 25 | cin>>d>>v>>u; 26 | if(u <= v || v == 0){ 27 | printf("Case %i: %s\n",t,"can't determine"); 28 | }else{ 29 | float diff = abs ((d / u) - (d / sqrt(u * u - v * v)));\ 30 | printf("Case %i: %.3f\n",t,diff); 31 | } 32 | t++; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /uva/Coin collector/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 7/30/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main2 { 9 | 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | int T = scanner.nextInt(); 13 | for (int i = 0; i < T; i++) { 14 | int n = scanner.nextInt(); 15 | ArrayList arrayList = new ArrayList<>(); 16 | for (int j = 0; j < n; j++) { 17 | int m = scanner.nextInt(); 18 | arrayList.add(m); 19 | } 20 | int ans = 1; 21 | int sum = 1; 22 | for (int j = 1; j < arrayList.size() - 1; j++) { 23 | if (sum + arrayList.get(j) < arrayList.get(j + 1)){ 24 | sum += arrayList.get(j); 25 | ans++; 26 | } 27 | } 28 | System.out.println(++ans); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /uva/Digit Counting/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = INT32_MIN; 10 | using namespace std; 11 | 12 | void fast() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(NULL); cout.tie(NULL); 15 | } 16 | 17 | 18 | int main() { 19 | fast(); 20 | int t; 21 | cin>>t; 22 | while(t--){ 23 | int n; 24 | cin>>n; 25 | int arr[10]; 26 | memset (arr,0,sizeof(arr)); 27 | for(int i = 1; i <= n; i++){ 28 | string st = to_string (i); 29 | for(unsigned int j = 0; j < st.length (); j++){ 30 | arr[st[j] - '0']++; 31 | } 32 | } 33 | for(int i = 0; i < 9; i++){ 34 | cout< 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = INT32_MIN; 10 | using namespace std; 11 | 12 | void fast() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(NULL); cout.tie(NULL); 15 | } 16 | 17 | 18 | int main() { 19 | fast(); 20 | double R,N; 21 | int t = 1; 22 | while(cin>>R>>N){ 23 | if((N == R) && N == 0){ 24 | break; 25 | } 26 | if(R - N < 0){ 27 | cout<<"Case "< arrayList[]; 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | while (true) { 11 | int n = scanner.nextInt(); 12 | int m = scanner.nextInt(); 13 | if (n == m && m == 0) 14 | break; 15 | arrayList = new ArrayList[n + 1]; 16 | for (int i = 0; i <= n; i++) { 17 | arrayList[i] = new ArrayList<>(); 18 | } 19 | 20 | for (int i = 0; i < m; i++) { 21 | int a = scanner.nextInt(); 22 | int b = scanner.nextInt(); 23 | arrayList[a].add(b); 24 | } 25 | Stack stack = new Stack(); 26 | boolean visited[] = new boolean[n + 1]; 27 | for (int i = 1; i <= n; i++) 28 | if (!visited[i]) 29 | topol(i, visited, stack); 30 | 31 | while (!stack.empty()) 32 | System.out.print(stack.pop() + " "); 33 | System.out.println(); 34 | } 35 | } 36 | 37 | private static void topol(int v, boolean visited[], 38 | Stack stack) 39 | { 40 | visited[v] = true; 41 | Integer i; 42 | for (Integer integer : arrayList[v]) { 43 | i = integer; 44 | if (!visited[i]) 45 | topol(i, visited, stack); 46 | } 47 | stack.push(v); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /uva/Scarecrow/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 7/30/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main2 { 9 | 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | int T = scanner.nextInt(); 13 | for (int i = 0; i < T; i++) { 14 | int n = scanner.nextInt(); 15 | String line = scanner.next(); 16 | int ans = 0; 17 | int a = line.charAt(0) == '#' ? 0 : 1; 18 | for (int j = 1; j < line.length(); j++) { 19 | if (a == 1){ 20 | ans++; 21 | j++; 22 | a = 0; 23 | }else{ 24 | if (line.charAt(j) == '.'){ 25 | a++; 26 | } 27 | } 28 | } 29 | if (a == 1){ 30 | ans++; 31 | } 32 | System.out.println("Case " + (i + 1) + ": " + ans); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /uva/UVa 10656 - Maximum Sum (II)/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 7/30/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main2 { 9 | 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | int k = 0; 13 | while (true) { 14 | int N = scanner.nextInt(); 15 | if (N == 0) { 16 | break; 17 | } 18 | ArrayList arrayList = new ArrayList<>(); 19 | for (int i = 0; i < N; i++) { 20 | int x = scanner.nextInt(); 21 | if (x != 0){ 22 | arrayList.add(x); 23 | } 24 | } 25 | for (int i = 0; i < arrayList.size(); i++) { 26 | if (i != arrayList.size() - 1) 27 | System.out.print(arrayList.get(i) + " "); 28 | else 29 | System.out.println(arrayList.get(i)); 30 | } 31 | if (arrayList.size() == 0){ 32 | System.out.println(0); 33 | } 34 | k++; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /uva/Watering grass/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = 999999; 10 | using namespace std; 11 | 12 | struct sprinkler{ 13 | double leftmost,rightmost,center; 14 | }; 15 | 16 | bool cmp(const sprinkler &i1, const sprinkler &i2) 17 | { 18 | return i1.leftmost < i2.leftmost; 19 | } 20 | 21 | 22 | int main(){ 23 | ios_base::sync_with_stdio(false); 24 | int n,l,w; 25 | while(cin>>n>>l>>w){ 26 | double x; 27 | double r; 28 | vector vec; 29 | for(int i = 0; i < n;i++){ 30 | sprinkler s; 31 | cin>>x>>r; 32 | if(r <= w/2){ 33 | continue; 34 | } 35 | s.leftmost = x - sqrt(r*r - (w * w)/4.0); 36 | s.rightmost = x + sqrt(r*r - (w * w)/4.0); 37 | s.center = x; 38 | vec.push_back (s); 39 | } 40 | sort(vec.begin (),vec.end (),cmp); 41 | int ans = 0; 42 | int i = 0; 43 | double prev = 0; 44 | for (; prev < l; ) { 45 | int flag = 0; 46 | double right = prev; 47 | 48 | for (; i < vec.size(); i++) { 49 | if (vec[i].leftmost > prev) { 50 | break; 51 | } 52 | if (vec[i].rightmost >= right) { 53 | right = vec[i].rightmost; 54 | flag = 1; 55 | } 56 | } 57 | 58 | if (flag == 0) { 59 | cout<<-1<= l) 66 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | while(true) 7 | { 8 | string div1, div2, div3, div4; 9 | cin >> div1; 10 | if(div1[0] == '0') 11 | break; 12 | cin >> div2 >> div3 >> div4; 13 | 14 | string id = div1 + div2 + div3 + div4; 15 | 16 | int oddsSum = 0; 17 | for(int i=0; i<16; i++) 18 | { 19 | if((i+1) % 2 == 1) 20 | { 21 | int adad = (id[i] - '0') *2; 22 | if(adad > 9) 23 | adad -= 9; 24 | oddsSum += adad; 25 | } 26 | else 27 | { 28 | oddsSum += id[i] - '0'; 29 | } 30 | } 31 | 32 | if(oddsSum % 10 == 0) 33 | cout << "Yes" << endl; 34 | else 35 | cout << "No" << endl; 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/Cake/Test.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Test { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int W = sc.nextInt(); 10 | int N = sc.nextInt(); 11 | int area=0; 12 | for (int i = 0; i < N; i++) { 13 | area+= sc.nextInt() * sc.nextInt(); 14 | } 15 | System.out.println(area/W); 16 | 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/Ceremony/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | #define ll long long 12 | 13 | 14 | int main() 15 | { 16 | int n; 17 | cin >> n; 18 | int borj[n]; 19 | 20 | for(int i=0; i> borj[i]; 22 | 23 | sort(borj, borj + n); 24 | int count = n; 25 | 26 | int attacks = 0; 27 | int mid, maxi = -1; 28 | 29 | int last = n-1; 30 | int chap = 0; 31 | int kasr = 0; 32 | while(count > 0) 33 | { 34 | if(borj[last] - kasr >= count) 35 | { 36 | count --; 37 | borj[last] = 0; 38 | last--; 39 | } 40 | else 41 | { 42 | kasr ++; 43 | for(int i=chap; i<=last; i++) 44 | { 45 | if(borj[i] == kasr) 46 | { 47 | borj[i] -= kasr; 48 | count --; 49 | chap ++; 50 | } 51 | else 52 | { 53 | break; 54 | } 55 | } 56 | } 57 | attacks ++; 58 | } 59 | 60 | cout << attacks; 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/Congestion Charging Zone/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int n; 12 | cin >> n; 13 | int ftime = 60*24; 14 | int ltime = 0; 15 | for(int i=0; i> time; 19 | //cout << time.substr(0, time.find(':')) << endl; 20 | //cout << time.substr(time.find(':')+1); 21 | int h = stoi(time.substr(0, time.find(':'))); 22 | int m = stoi(time.substr(time.find(':')+1)); 23 | int t = (h*60) + m; 24 | //cout << "time = " << t <= (6 * 60) + 30 && t <= 19*60) 26 | { 27 | if(t < ftime) 28 | ftime = t; 29 | if(t > ltime) 30 | ltime = t; 31 | } 32 | } 33 | //cout <<"ftime = "< s1+s2) 12 | cout << "Persepolis"; 13 | else if(p2 < s1) 14 | cout << "Esteghlal"; 15 | else 16 | cout << ((p2 > s1) ? "Persepolis" : "Penalty"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/gitKeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/gitkeep2: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/آخ جون طرف نیست!/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | public class Test { 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | List orginal = new ArrayList(); 9 | List arr = new ArrayList(); 10 | String str = ""; 11 | int n = 0; 12 | 13 | orginal.add(0, "shanbe"); 14 | for(int i=1; i<6; i++) 15 | orginal.add(i, i+"shanbe"); 16 | orginal.add(6, "jome"); 17 | 18 | 19 | int one = sc.nextInt(); 20 | for(int i=0; i100) 22 | num = 100; 23 | else if(num<0) 24 | num = 0; 25 | for (int i=1; i<=num; i++) 26 | System.out.println("man khoshghlab hastam"); 27 | } 28 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اتل متل توتوله/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main() 6 | { 7 | int n, k; 8 | cin >> n >> k; 9 | vector pa; 10 | for(int i=1; i<= 2*n; i++) 11 | pa.push_back((i+1)/2); 12 | 13 | int curr = 0, cu; 14 | while((int)pa.size() > 1) 15 | { 16 | cout << pa[curr] << " "; 17 | for(int i=1; i 2 | // 3 | #include 4 | using namespace std; 5 | #define ll long long 6 | ll max(int a,ll b){ return max((ll)a,b);} 7 | ll min(int a,ll b){ return min((ll)a,b);} 8 | ll min(ll a,int b){ return min(a,(ll)b);} 9 | ll max(ll a,int b){ return max(a,(ll)b);} 10 | 11 | int main() 12 | { 13 | //int t; cin >> t; while(t--) solve(); 14 | int n, m, q, t, a; 15 | cin >> n >> m; 16 | int chi[n]; 17 | for(int i=0; i> chi[i]; 18 | 19 | cin >> q; 20 | vector com[q]; 21 | int ted[q]; 22 | for(int i=0; i> t; 25 | com[i].resize(t); 26 | for(int j=0; j> com[i][j]; 28 | cin >> ted[i]; 29 | for(int j=0; j m) 39 | continue; 40 | cnt = 0; 41 | for(int j=0; j max) 32 | max = number[i]; 33 | } 34 | System.out.println(max); 35 | sc.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اسم ها/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | 8 | // Better Solution 9 | 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int n = sc.nextInt(); 13 | String names; 14 | 15 | int [] number = new int[n]; 16 | for (int i = 0; i < n; i++) { 17 | int count=0; 18 | names = sc.next(); 19 | char[] chars = names.toCharArray(); 20 | for (int j = 0; j < names.length(); j++) { 21 | for (int k = j+1; k < names.length(); k++) { 22 | if (chars[j] == chars[k] && chars[j] !=' ') { 23 | count++; 24 | chars[k] = ' '; //Set chars[k] to ' ' to avoid printing visited character 25 | } 26 | } 27 | } 28 | number[i] = names.length()-count; 29 | } 30 | int max = number[0]; 31 | for (int i = 0; i < number.length; i++) { 32 | if (number[i] > max) 33 | max = number[i]; 34 | } 35 | System.out.println(max); 36 | sc.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اسنپ در شکرستان/Test2.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Test2 { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(), m = sc.nextInt(); 9 | int [][] array = new int[n+1][n+1]; 10 | int result = 0; 11 | 12 | for (int i = 1; i <= n; i++) { 13 | for (int j = 1; j <= n; j++) { 14 | array[i][j] = sc.nextInt(); 15 | } 16 | } 17 | 18 | for (int i = 0; i < m; i++) { 19 | int x = sc.nextInt() , y = sc.nextInt(); 20 | result += array[x][y]; 21 | } 22 | 23 | System.out.println(result); 24 | 25 | sc.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اعداد اول/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | int counter = 0; 13 | 14 | if(a < 1 || b > 10000) 15 | return; 16 | 17 | for(int i=a; i<=b;i++) { 18 | for (int j=1; j<=i; j++) 19 | { 20 | if(i%j==0) 21 | counter++; 22 | } 23 | if(counter==2) 24 | System.out.println(i); 25 | counter=0; 26 | } 27 | 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اعداد اول/PrimeNumbers.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | b = int(input()) 3 | 4 | def isPrime(n): 5 | if n>1: 6 | for i in range(2,n): 7 | if (n%i) == 0: 8 | return False 9 | return True 10 | else: 11 | return False 12 | 13 | 14 | for i in range(a,b+1): 15 | if isPrime(i): 16 | print(i) 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/ام تایی ها/solution.py: -------------------------------------------------------------------------------- 1 | def calculator(n, m, li): 2 | overall_l = [] 3 | number_of_sub_lists = int((n / m) + (n % m)) 4 | gp = 0 5 | counter = 0 6 | 7 | for a in range(number_of_sub_lists): # Create m sub list in overall list 8 | lst = [] 9 | overall_l.append(lst) 10 | 11 | while counter + m <= n: # Filling sub lists 12 | for j in range(counter, counter + m): 13 | overall_l[gp].append(li[j]) 14 | gp += 1 15 | counter += m 16 | 17 | for k in range(counter, n): # Adding remaining of original list to overall list 18 | overall_l[gp].append(li[k]) 19 | 20 | sum_of_overall_l = [] 21 | for item in range(len(overall_l)): # Calculate sum of each list and add to new list 22 | sum_of_overall_l.append(sum(overall_l[item])) 23 | 24 | temp = sum_of_overall_l[0] 25 | step = 1 26 | for z in range(len(sum_of_overall_l)): 27 | if (step + 1 <= len(sum_of_overall_l)) and (step % 2 != 0): 28 | temp -= sum_of_overall_l[step] 29 | step += 1 30 | elif (step + 1 <= len(sum_of_overall_l)) and (step % 2 == 0): 31 | temp += sum_of_overall_l[step] 32 | step += 1 33 | return temp 34 | 35 | 36 | # print(calculator(8, 3, [1, 2, 3, 4, 5, 6, 7, 8])) 37 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/ام سین/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int user_input = sc.nextInt(); 7 | String [] sofre = {"ib","amano","enjed","abze","aat","eke","erke","omaq","ir"}; 8 | for (int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | long long n, k; 7 | cin >> n >> k; 8 | pair a[n]; 9 | for(int i=0; i> a[i].first >> a[i].second; 10 | sort(a, a+n); 11 | 12 | for(int i=0; i= a[i].first && a[i].first < a[i].second) 15 | { 16 | k -= a[i].first; 17 | k += a[i].second; 18 | } 19 | } 20 | 21 | cout << k << endl; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اوقات فراغت/Test4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test4 { 4 | // 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt() , m = sc.nextInt(); 8 | sc.nextLine(); 9 | String[] str = new String[n]; 10 | 11 | for (int i = 0; i < n; i++) { 12 | 13 | str[i] = sc.nextLine(); //getting strings 14 | 15 | } 16 | 17 | String s = sc.nextLine(); // getting desire string 18 | int size = s.length(); 19 | int count = 0 , difference = 0; 20 | 21 | for (int i = 0; i < n; i++) { 22 | for (int j = 0; j <= m - size; j++) { 23 | difference = 0; 24 | for (int k = 0; k 1: 8 | for i in range(2,n): 9 | if (n%i) == 0: 10 | return False 11 | return True 12 | else: 13 | return False 14 | 15 | 16 | for i in range(a+1,b): 17 | if isPrime(i): 18 | result.append(str(i)) 19 | 20 | print(",".join(result)) 21 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/اول‌بینی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | int count; 13 | String result = ""; 14 | for(int i=a+1;i= 2 and abs(j-4) >= 2: 14 | if abs(i-4) == 3 and abs(j-4) == 3: 15 | if barcode[i][j] == '1': 16 | able = False 17 | else: 18 | if barcode[i][j] == '0': 19 | able = False 20 | elif barcode[i][j] == '2': 21 | halat *= 2 22 | 23 | if able is False: 24 | print(0) 25 | else: 26 | print(halat) 27 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بازرگانی سوکرات و پسران/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | int n ; 6 | int [][] a; 7 | int [] x; 8 | int sum = 0; 9 | int min = Integer.MAX_VALUE; 10 | int [] ans; 11 | public Main(int n, int [][] a) { 12 | this.a = a; 13 | this.n = n; 14 | x = new int [n]; 15 | ans = new int [n]; 16 | work_selection(0); 17 | for (int i = 0; i < n; i++) { 18 | System.out.println(ans[i]); 19 | } 20 | } 21 | 22 | void work_selection(int i){ 23 | if(i == n){ 24 | min = sum; 25 | for (int j = 0; j < n; j++) { 26 | ans[j] = x[j]; 27 | } 28 | } 29 | else{ 30 | for (int k = 0; k < n; k++) { 31 | if(is_ok(k, i)){ 32 | x[i] = k; 33 | sum += a[i][k]; 34 | work_selection(i + 1); 35 | sum -= a[i][k]; 36 | } 37 | } 38 | } 39 | 40 | } 41 | 42 | boolean is_ok(int k, int i){ 43 | for (int j = 0; j < i; j++) { 44 | if(x[j] == k) 45 | return false; 46 | } 47 | if(sum + a[i][k] > min) 48 | return false; 49 | return true; 50 | } 51 | 52 | public static void main(String[] args) { 53 | Scanner sc = new Scanner(System.in); 54 | int n = sc.nextInt(); 55 | int a [][] = new int [n][n]; 56 | for (int i = 0; i < n; i++) { 57 | for (int j = 0; j < n; j++) { 58 | a[i][j] = sc.nextInt(); 59 | } 60 | } 61 | new Main(n, a); 62 | } 63 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بازگشت از بوستان/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int x = sc.nextInt(); 12 | sc.nextInt(); 13 | 14 | int x1 = sc.nextInt(); 15 | sc.nextInt(); 16 | 17 | if (x1 > x) 18 | System.out.println("Right"); 19 | else 20 | System.out.println("Left"); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بازی کلمه ها/practice.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | 4 | def words_check(text): 5 | new_list = [] 6 | l = text.split() 7 | for item in l: 8 | word = "" 9 | s = 0 10 | for i in item: 11 | if i.isalpha(): 12 | s += 1 13 | word += i 14 | if (s / len(item)) > 0.5: 15 | new_list.append(word.capitalize()) 16 | return Counter(new_list) 17 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/باقر حال نداره ولی پول داره/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | int n = scanner.nextInt(); 7 | int m = scanner.nextInt(); 8 | int A[] = new int[11]; 9 | for (int i = 1; i <= n; i++) { 10 | A[i] = scanner.nextInt(); 11 | } 12 | int memo[][] = new int[10001][11]; 13 | int INF = 1000000000; 14 | for (int i = 1; i <= m; i++) { 15 | memo[i][0] = INF; 16 | } 17 | for (int j = 1; j <= n; j++) { 18 | for (int i = 0; i <= m; i++) { 19 | memo[i][j] = INF; 20 | for (int k = 1; k*k <= i; k++) { 21 | if (memo[i][j] > memo[i - k * k][j - 1] + (A[j] - k) * (A[j] - k)) { 22 | memo[i][j] = memo[i - k * k][j - 1] + (A[j] - k) * (A[j] - k); 23 | } 24 | } 25 | } 26 | } 27 | if (memo[m][n]==INF){ 28 | System.out.println(-1); 29 | }else{ 30 | System.out.println(memo[m][n]); 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/باقر خسته ست ولی بی فرهنگ نه/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int l = sc.nextInt(); 12 | 13 | int time = 0; // keep track of spending time on the path 14 | int delay = 0; 15 | int d = 0 , r = 0, g = 0, masafat = 0; 16 | 17 | 18 | for (int i = 0; i < n; i++) { // number of lights 19 | // for (int j = 1; j <= 3; j++) { // number of parameters per light 20 | // if (j == 1){ 21 | d = sc.nextInt(); 22 | r = sc.nextInt(); 23 | g = sc.nextInt(); 24 | 25 | time += Math.abs(d - masafat); 26 | masafat = d; 27 | 28 | while (time % (r + g) < r) { 29 | time++; 30 | } 31 | } 32 | 33 | time += Math.abs(l - masafat); 34 | 35 | 36 | // if (i==0) 37 | // time = d; 38 | // else { 39 | // d = Math.abs(d - preLight); 40 | // time += d; 41 | // } 42 | // } 43 | // else if (j == 2){ 44 | 45 | // if (i==0 & time < r) { 46 | // delay += Math.abs(time - r); 47 | // time += delay; 48 | // } 49 | // else if (i == 0 & time >= r) 50 | // continue; 51 | // else if ( time < (r+d)) { 52 | // delay += Math.abs(time - (r+d)); 53 | // time += delay; 54 | // } 55 | // } 56 | // else{ 57 | // preLight = d; 58 | // } 59 | // } 60 | // if (i>1) 61 | // time = Math.abs(time-d); 62 | // } 63 | 64 | System.out.println(time); 65 | 66 | 67 | sc.close(); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/باقر مخالف است/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * @Author: Quera College 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int x=sc.nextInt(); 11 | int []cntx=new int[10]; 12 | int extraX=x; 13 | while(extraX>0) 14 | { 15 | cntx[extraX%10]++; 16 | extraX/=10; 17 | } 18 | for(int y=x+1;y<=1000*1000;y++) 19 | { 20 | int []cnty=new int[10]; 21 | int extraY=y; 22 | while(extraY>0) 23 | { 24 | cnty[extraY%10]++; 25 | extraY/=10; 26 | } 27 | boolean equal=true; 28 | for(int i=0;i<=9;i++) 29 | if(cntx[i]!=cnty[i]) 30 | { 31 | equal=false; 32 | break; 33 | } 34 | if(equal) 35 | { 36 | System.out.println(y); 37 | return ; 38 | } 39 | } 40 | System.out.println(0); 41 | 42 | sc.close(); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/باقر مخالف است/Test4.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * @Author: Stackoverflow 5 | */ 6 | 7 | public class Test4 { 8 | 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | String e = sc.nextLine(); 13 | if (nextHighest(e) != null) 14 | System.out.println(nextHighest(e)); 15 | else 16 | System.out.println(0); 17 | 18 | sc.close(); 19 | } 20 | 21 | public static String nextHighest(String e) { 22 | char[] digits = e.toCharArray(); 23 | 24 | int i = digits.length - 2; 25 | 26 | NavigableSet set = new TreeSet<>(); 27 | for (; i >= 0; i--) { 28 | 29 | 30 | char[] shortList = Arrays.copyOfRange(digits, i, digits.length); 31 | 32 | 33 | String originalTail = new String(shortList); 34 | 35 | permute(shortList, digits.length - i, set); 36 | 37 | 38 | String minTail = set.higher(originalTail); 39 | 40 | if (minTail != null) { 41 | String head = 42 | new String(Arrays.copyOfRange(digits, 0, i)); 43 | return String.format("%s%s", head, minTail); 44 | } 45 | // clear the set and try a larger ending. 46 | set.clear(); 47 | } 48 | // no success, return the original value. 49 | return null; 50 | } 51 | 52 | public static void permute(char[] elements, int length, 53 | Set vals) { 54 | if (length == 1) { 55 | vals.add(new String(elements)); 56 | } else { 57 | for (int i = 0; i < length; i++) { 58 | permute(elements, length - 1, vals); 59 | if (length % 2 == 1) { 60 | swap(elements, 1, length - 1); 61 | } else { 62 | swap(elements, i, length - 1); 63 | } 64 | } 65 | } 66 | 67 | } 68 | 69 | public static void swap(char[] list, int i, int j) { 70 | char temp = list[i]; 71 | list[i] = list[j]; 72 | list[j] = temp; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بالین/calculator.py: -------------------------------------------------------------------------------- 1 | def calculate_floor(string): 2 | floor = 0 3 | for i in range(len(string)): #OR for c in string: 4 | if string[i] == "U": # if c == "U": 5 | floor +=1 6 | else: 7 | floor -=1 8 | return floor 9 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بتایپ/Test.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.*; 4 | 5 | public class Test{ 6 | 7 | public static void main(String[] args) { 8 | // write your code here 9 | Scanner input =new Scanner(System.in); 10 | 11 | StringBuilder sb =new StringBuilder(); 12 | 13 | String s = input.next(); 14 | Stack stack =new Stack<>(); 15 | 16 | for (char c: s.toCharArray()) { 17 | if (c == '=') 18 | try { 19 | stack.pop(); 20 | }catch (EmptyStackException ignored ){} 21 | 22 | else 23 | stack.push(c); 24 | } 25 | 26 | for (char c:stack) { 27 | sb.append(c); 28 | } 29 | 30 | System.out.println(sb.toString()); 31 | 32 | 33 | 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بدخواه پویان/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int p = sc.nextInt(); 11 | int d = sc.nextInt(); 12 | 13 | 14 | for (int i = 1; i < 10; i++) { 15 | int s = (d*i)%p; 16 | if (s<=p/2 & s>=0) { 17 | System.out.println(d*i); 18 | break; 19 | } 20 | } 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بلندگو/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | String n = sc.nextLine(); 8 | char [] chars = new char[n.length()]; 9 | 10 | for(int i=0;i= table.length) return false; 67 | return j >= 0 && j < table[i].length; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/بهداشت و سلامت/Test.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.*; 4 | 5 | public class Test{ 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int x = sc.nextInt(); 11 | int n = sc.nextInt(); 12 | int def = 0; 13 | if (n == 0) 14 | System.out.println(20); 15 | else if (n == 7) 16 | System.out.println(x); 17 | else { 18 | def = x - n; 19 | if (def < 0) 20 | System.out.println(0); 21 | else 22 | System.out.println(x - n); 23 | 24 | } 25 | 26 | 27 | } 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تاریخ تولد/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static Scanner sc; 5 | public static void main(String[] args) { 6 | sc = new Scanner(System.in); 7 | 8 | String string = sc.nextLine(); 9 | String numYear = ""; 10 | String numMonth = ""; 11 | 12 | int counter = 0; 13 | 14 | for (char ch : string.toCharArray()) { 15 | counter++; 16 | if(counter <= 2) { 17 | numYear = numYear + Character.toString(ch); 18 | } else { 19 | numMonth = numMonth + Character.toString(ch); 20 | } 21 | } 22 | 23 | System.out.println("saal:" + numYear); 24 | System.out.println("maah:" + numMonth); 25 | } 26 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تتریس/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | using namespace std; 4 | ll n, k; 5 | ll a[1000001]; 6 | ll ans = 0; 7 | int mid_max(int l, int r) 8 | { 9 | int maxi=-1, max_id; 10 | int mid = (l+r)/2; 11 | for(int i=l; i<=r; i++) 12 | { 13 | if(a[i] > maxi) 14 | maxi = a[i], max_id=i; 15 | else if(a[i] == maxi && abs(mid-i) < abs(mid-max_id)) 16 | max_id = i; 17 | } 18 | return max_id; 19 | } 20 | 21 | void solve(int l, int r, int e) 22 | { 23 | if(l > r) return; 24 | if(l == r) 25 | { 26 | ans += k-(a[l]+e); 27 | return; 28 | } 29 | int midmax = mid_max(l, r); 30 | 31 | ans += k - (a[midmax]+e); 32 | e += k - (a[midmax]+e); 33 | solve(l, midmax-1, e); 34 | solve(midmax+1, r, e); 35 | } 36 | 37 | int main() 38 | { 39 | cin >> n; 40 | for(int i=0; i> a[i]; 41 | ll* max_id = max_element(a, a+n); 42 | k = *max_id; 43 | solve(0, n-1, 0); 44 | cout << ans << endl; 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تخطی گری/source.py: -------------------------------------------------------------------------------- 1 | print(*sorted([i.lower() if (ord(i) - 97) % 2 == 0 else i.upper() for i in input()], reverse=True)) -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تخفیف جشنواره/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n, x; 8 | cin >> n >> x; 9 | int ajnas[n]; 10 | for(int i=0; i> ajnas[i]; 13 | } 14 | 15 | sort(ajnas, ajnas + n); 16 | 17 | int tedad = -1; 18 | if(n == 1) 19 | { 20 | tedad = 1; 21 | } 22 | else 23 | { 24 | for(int i=1; i x) 27 | { 28 | tedad = i; 29 | break; 30 | } 31 | } 32 | } 33 | 34 | 35 | if(tedad == -1) 36 | { 37 | tedad = n; 38 | } 39 | 40 | cout << tedad; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تطابق رشته/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | const int mod = 1e9+7; 5 | int main() 6 | { 7 | string s, t; 8 | cin >> s >> t; 9 | int mini, maxi; 10 | ll len = 0, cnt = 1; 11 | for(char a='a'; a<='z'; a++) 12 | { 13 | mini = min(count(s.begin(), s.end(), a), count(t.begin(), t.end(), a)); 14 | maxi = max(count(s.begin(), s.end(), a), count(t.begin(), t.end(), a)); 15 | if(mini == 0) continue; 16 | len += mini; 17 | for(int i=maxi; i>maxi-mini; i--) 18 | cnt = (cnt*i) % mod; 19 | } 20 | 21 | cout << len << " " << cnt << endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تو چقدر اضافه وزن داری؟/Main.java: -------------------------------------------------------------------------------- 1 | import java.math.RoundingMode; 2 | import java.text.DecimalFormat; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | static Scanner sc; 7 | public static void main(String[] args) { 8 | sc = new Scanner(System.in); 9 | 10 | float WeightInKilograms = sc.nextFloat(); 11 | float HeightInMeters = sc.nextFloat(); 12 | 13 | if(WeightInKilograms < 1 || WeightInKilograms > 200) 14 | return; 15 | 16 | if(HeightInMeters < 1 || HeightInMeters > 10) 17 | return; 18 | 19 | float BMI = WeightInKilograms / (HeightInMeters * HeightInMeters); 20 | 21 | DecimalFormat df = new DecimalFormat("#.00"); 22 | df.setRoundingMode(RoundingMode.CEILING); 23 | 24 | System.out.println(df.format((double) Math.round(BMI * 100) / 100)); 25 | 26 | if(BMI < 18.5) 27 | System.out.println("Underweight"); 28 | else if(BMI >= 18.5 && BMI < 25) 29 | System.out.println("Normal"); 30 | else if(BMI >= 25 && BMI < 30) 31 | System.out.println("Overweight"); 32 | else if(BMI > 30) 33 | System.out.println("Obese"); 34 | 35 | } 36 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تو چقدر اضافه وزن داری؟/Main2.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main2 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int n = sc.nextInt(); 12 | float m = sc.nextFloat(); 13 | 14 | float BMI = n / (m*m); 15 | 16 | System.out.println(String.format("%.2f",BMI)); 17 | 18 | if (BMI <18.5) 19 | System.out.println("Underweight"); 20 | else if (BMI >= 18.5 & BMI <25) 21 | System.out.println("Normal"); 22 | else if (BMI >= 25 & BMI <30) 23 | System.out.println("Overweight"); 24 | else 25 | System.out.println("Obese"); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/توان دو/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static Scanner scanner; 5 | public static void main(String[] args) { 6 | scanner = new Scanner(System.in); 7 | int n = Integer.parseInt(scanner.nextLine()); 8 | int tavan = 2; 9 | 10 | for(int i = 0 ; i <= n ; i++) { 11 | tavan *= 2; 12 | if(tavan >= n) { 13 | System.out.println(tavan); 14 | break; 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/توان دو/power2.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | 3 | for i in range (0,a+1): 4 | if 2**i > a: 5 | print(2**i) 6 | break 7 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تک رقمی/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | long n =sc.nextLong(); 11 | 12 | n = n % 9; 13 | if (n==0) 14 | System.out.print(9); 15 | else 16 | System.out.println(n); 17 | 18 | sc.close(); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تک رقمی/practice.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | n = n % 9 3 | if n == 0: 4 | print(9) 5 | else: 6 | print(n) 7 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تی شرت برنده/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | int xt = in.nextInt(), yt = in.nextInt(), xp = in.nextInt(), yp = in.nextInt(); 8 | 9 | 10 | 11 | if ( (xt>=xp) & (yt>=yp)) 12 | System.out.println("yes"); 13 | else 14 | System.out.println("no"); 15 | 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/تیله های توی کیسه/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, d; 9 | cin >> n >> d; 10 | int tile[n]; 11 | for(int i=0; i> tile[i]; 13 | 14 | int num=0; 15 | int index = -1; 16 | int maxsMinimum = 1000000000; 17 | int m = -1; 18 | for(int i=0; i= 4 and ( 6 | len(value) >= 6) and not value.isnumeric(): 7 | lst.append(key) 8 | return lst 9 | 10 | 11 | # print(check_registration_rules(username='password', sadegh='He3@lsa', quera='kLS45@l$')) 12 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/جاده کشی/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test { 4 | 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int row = n / 2; 10 | int col = (n % 2) + row; 11 | 12 | System.out.print((row + 1) * (col + 1)); 13 | sc.close(); 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/جاده کشی/practice.py: -------------------------------------------------------------------------------- 1 | 2 | n = int(input()) 3 | row = int(n / 2) 4 | col = int((n%2) + row) 5 | print((row+1) * (col+1)) -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/جایگشت‌ها/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * Created by AMK on 8/2/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int n = scanner.nextInt(); 12 | int arr[] = new int[n + 1]; 13 | for (int i = 1; i <= n; i++) { 14 | int x = scanner.nextInt(); 15 | for (int j = 1; j < arr.length; j++) { 16 | if (arr[j] == 0){ 17 | int k = 0, kk = j; 18 | while (k < x){ 19 | if (arr[kk] == 0) { 20 | k++; 21 | } 22 | kk++; 23 | } 24 | if (k == x) { 25 | while (arr[kk] != 0) 26 | kk++; 27 | arr[kk] = i; 28 | break; 29 | } 30 | } 31 | } 32 | } 33 | for (int i = 1; i < arr.length - 1; i++) { 34 | System.out.print(arr[i] + ","); 35 | } 36 | System.out.println(arr[arr.length - 1]); 37 | } 38 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/جدول ضرب گنده/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | 12 | if(n < 1 || n > 100) 13 | return; 14 | 15 | for(int i=1; i <=n; i++) { 16 | for (int j=1; j<=n; j++) { 17 | System.out.print(i*j); 18 | System.out.print(" "); 19 | } 20 | System.out.println(""); 21 | } 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/جدی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | vector don; 10 | don.resize(n); 11 | for(int i=0; i> don[i]; 13 | 14 | 15 | bool soodi = false; 16 | bool nozoli = true; 17 | int tol = 1; 18 | for(int j=0; j 20) 14 | return; 15 | 16 | String[] inputNumbers = new String[n]; 17 | 18 | int max_len = 0; 19 | 20 | for (int i = 1; i <= n; i++) { 21 | inputNumbers[i-1] = sc.nextLine(); 22 | 23 | if(max_len < inputNumbers[i-1].length()) 24 | max_len = inputNumbers[i-1].length(); 25 | } 26 | 27 | String[][] myNumbers = new String[n][max_len]; 28 | int j = 0; 29 | 30 | for (int i = 1; i <= n; i++) { 31 | for (j = 0; j < max_len; j++) { 32 | myNumbers[i-1][j] = "0"; 33 | } 34 | } 35 | 36 | int temp_len = 0; 37 | for (int i = 1; i <= n; i++) { 38 | temp_len = inputNumbers[i-1].length(); 39 | j = max_len - temp_len; 40 | for (char ch:inputNumbers[i-1].toCharArray()) { 41 | myNumbers[i-1][j] = String.valueOf(ch); 42 | j++; 43 | } 44 | } 45 | 46 | String sumNumbers = ""; 47 | int sum = 0; 48 | int borrow = 0; 49 | 50 | for(j = max_len - 1; j >= 0; j--) { 51 | for (int i = 1; i <= n; i++) { 52 | sum += Integer.parseInt(myNumbers[i-1][j]); 53 | } 54 | 55 | sum += borrow; 56 | borrow = 0; 57 | 58 | if(sum > 9) { 59 | borrow = sum / 10; 60 | sum = sum - (borrow * 10); 61 | } 62 | 63 | sumNumbers = String.valueOf(sum) + sumNumbers; 64 | sum = 0; 65 | } 66 | 67 | if(borrow!=0) { 68 | max_len++; 69 | System.out.print(String.valueOf(borrow)); 70 | } 71 | 72 | System.out.println(sumNumbers); 73 | 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/حرکت روی ظروف/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | float a = sc.nextFloat() , b = sc.nextFloat(), c=sc.nextFloat() , avg; 8 | 9 | avg = (a+b+c)/3; 10 | if ((a == b) && (b==c)) 11 | System.out.println(0); 12 | else if (a==avg || b==avg || c==avg) 13 | System.out.println(1); 14 | else 15 | System.out.println(2); 16 | sc.close(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خب باقر سرما خورده/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | /** 5 | * @Author: Mohammadyar Barandov 6 | * 7 | */ 8 | 9 | public class Test { 10 | 11 | public static void main(String[] args) { 12 | Scanner input = new Scanner(System.in); 13 | String[] strings = new String[6]; 14 | for (int i = 1; i <= 5; i++) { 15 | strings[i] = input.nextLine(); 16 | } 17 | int nf=0; 18 | for (int i = 1; i <= 5; i++) { 19 | if (strings[i].contains("HAFEZ") | strings[i].contains("MOLANA")) 20 | System.out.print(i+" "); 21 | else nf++; 22 | } 23 | if (nf==5) 24 | System.out.println("NOT FOUND!"); 25 | 26 | input.close(); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خر در چمن فراوونه!!/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Test { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt() , b = sc.nextInt() , l = sc.nextInt(), sum = 0; 9 | for (int i = 1; i <=l ; i++) { 10 | if (i%2 == 0) 11 | sum+=b; 12 | else 13 | sum+=a; 14 | } 15 | System.out.println(sum); 16 | 17 | sc.close(); 18 | 19 | } 20 | 21 | 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خریدار ناشی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner in = new Scanner(System.in); 7 | int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); 8 | int[][] p = new int[n][m]; 9 | for (int i = 0; i < k; i++) { 10 | p[in.nextInt() - 1][in.nextInt() - 1] = 1; 11 | } 12 | if (k % 2 > 0) { 13 | System.out.println("0"); 14 | } else if (k == n * m) { 15 | System.out.println("-1"); 16 | } else { 17 | a: 18 | for (int i = 0; i < n; i++) { 19 | for (int j = 0; j < m; j++) { 20 | if (p[i][j] == 0) { 21 | System.out.println("1\n" + (i + 1) + " " + (j + 1)); 22 | break a; 23 | } 24 | } 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خواب پوپک/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | int x = sc.nextInt(); 13 | 14 | int count = 0; 15 | 16 | for (int i = 1; i <= a; i++) 17 | if (a % i == 0) 18 | for (int j = 1; j <= b; j++) 19 | if (b % j == 0) 20 | if (i + j <= x) 21 | count++; 22 | 23 | System.out.println(count); 24 | 25 | 26 | sc.close(); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خوش آمد/khoshAmad.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | print("Hello CodeCup ",n,"!",sep='') 4 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/خیلی قهوه ای یا باج یا خوش‌خوار/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a[3]; 7 | cin >> a[0] >> a[1] >> a[2]; 8 | bool able[3] = {false}; 9 | int evens = 0, odds = 0; 10 | for(int i=0; i<3; i++) 11 | { 12 | if(a[i] % 2 == 0) 13 | { 14 | evens ++; 15 | } 16 | else 17 | { 18 | odds ++; 19 | } 20 | } 21 | 22 | if(odds == 1 && evens == 2) 23 | { 24 | for(int i=0; i<3; i++) 25 | { 26 | if(a[i] % 2 == 1) 27 | { 28 | able[i] = true; 29 | break; 30 | } 31 | } 32 | } 33 | else if(odds == 2 && evens == 1) 34 | { 35 | for(int i=0; i<3; i++) 36 | { 37 | if(a[i] % 2 == 0) 38 | { 39 | able[i] = true; 40 | break; 41 | } 42 | } 43 | } 44 | 45 | for(int i=0; i<3; i++) 46 | { 47 | if(able[i]) 48 | cout << "YES "; 49 | else 50 | cout << "NO "; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/دایره عجیب/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int k = sc.nextInt(); 12 | int count=0; 13 | int current=0; 14 | 15 | while(true){ 16 | count++; 17 | current+=k; 18 | current %=n; 19 | if (current == 0) 20 | break; 21 | } 22 | System.out.println(count); 23 | 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/دایره عجیب/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = 999999; 10 | using namespace std; 11 | 12 | int main(){ 13 | ios_base::sync_with_stdio(false); 14 | int n,k; 15 | cin>>n>>k; 16 | int x = k; 17 | int i = 1; 18 | x = x% n; 19 | while(x != 0){ 20 | i++; 21 | x += k; 22 | x = x % n; 23 | } 24 | cout< 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m, k; 10 | cin >> n >> m >> k; 11 | bool mojod[n] = {false}; 12 | vector can; 13 | int temp; 14 | for(int i=0; i> temp; 17 | mojod[temp-1] = true; 18 | can.push_back(temp); 19 | } 20 | 21 | vector vakonesh[k][2]; 22 | for(int i=0; i> p >> q; 26 | 27 | for(int j=0; j> temp; 30 | vakonesh[i][0].push_back(temp); 31 | } 32 | 33 | for(int j=0; j> temp; 36 | vakonesh[i][1].push_back(temp); 37 | } 38 | } 39 | bool oks[k] = {false}; 40 | int vsize; 41 | bool changed = false; 42 | for(int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t; 9 | cin >> t; 10 | string pasokh[t]; 11 | for(int i=0; i> n >> k; 15 | 16 | int polis[k][2]; 17 | for(int j=0; j> polis[j][0]; 20 | cin >> polis[j][1]; 21 | } 22 | 23 | if(k <= 1 || n == 3) 24 | { 25 | pasokh[i] = "Yes"; 26 | continue; 27 | } 28 | 29 | qsort(polis, k, sizeof(*polis), 30 | [](const void *arg1, const void *arg2)->int 31 | { 32 | int const *lhs = static_cast(arg1); 33 | int const *rhs = static_cast(arg2); 34 | return (lhs[0] < rhs[0]) ? -1 35 | : ((rhs[0] < lhs[0]) ? 1 36 | : (lhs[1] < rhs[1] ? -1 37 | : ((rhs[1] < lhs[1] ? 1 : 0)))); 38 | }); 39 | 40 | for(int j=1; j 2 | using namespace std; 3 | 4 | int team[1<<17]; // 1<<17 is equal to 2^17, maximum of team counts 5 | long long calculate(int l, int r) 6 | { 7 | if(l == r) // if l==r then this is last team so we should return power of this team 8 | return team[l]; 9 | int mid = (l+r)/2; 10 | long long c1 = calculate(l, mid); //maximum possibe of gift if we choose left 11 | long long c2 = calculate(mid+1, r); //maximum possibe of gift if we choose right 12 | int max1 = *max_element(team+mid+1, team+r+1); // maximum power of right(for choosing left) 13 | int max2 = *max_element(team+l, team+mid+1); // maximum power of left(for choosing right) 14 | 15 | return max(c1 + max1, c2 + max2); // return maximum of choosing left or right 16 | } 17 | 18 | int main() 19 | { 20 | int n; 21 | cin >> n; 22 | for(int i=0; i<(1<> team[i]; 24 | 25 | cout << calculate(0, (1< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,m; 7 | cin >> n >> m; 8 | bool wall[n][m], win; 9 | string temp; 10 | for(int i=0; i> temp; 13 | for(int j=0; j 0 && wall[i-1][j-1] != wall[i][j-1]) 30 | { 31 | cout << "bad wall"; 32 | return 0; 33 | } 34 | } 35 | } 36 | else 37 | { 38 | if(win) 39 | { 40 | win = false; 41 | if(wall[i-1][j] != wall[i][j]) 42 | { 43 | cout << "bad wall"; 44 | return 0; 45 | } 46 | } 47 | } 48 | } 49 | } 50 | 51 | cout << "good wall"; 52 | } 53 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رشته فیبوناچی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int num = sc.nextInt(); 11 | 12 | int arr[] = new int[101]; 13 | arr[0] = 1; 14 | arr[1] = 2; 15 | for (int i = 2; i <= 100; i++) { 16 | arr[i] = arr[i-1] + arr[i-2]; 17 | } 18 | 19 | int j = 0; 20 | for (int i = 1; i <= num; i++) { 21 | if(i == arr[j]) 22 | { 23 | System.out.print("+"); 24 | j++; 25 | } 26 | else 27 | System.out.print("-"); 28 | } 29 | 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رشته مورد علاقه/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string a; 8 | cin >> a; 9 | int alen = a.length(); 10 | 11 | int n; 12 | cin >> n; 13 | 14 | string rs[n]; 15 | for(int i=0; i> rs[i]; 17 | 18 | int tedad = 0; 19 | for(int i=0; i 2 | using namespace std; 3 | 4 | int good[26] = {0}; 5 | int dp[1001][26] = {0}; 6 | int k; 7 | bool check(int r) 8 | { 9 | for(int i=0; i<26; i++) 10 | { 11 | if(r == k-1) 12 | { 13 | if(dp[r][i] > good[i]) 14 | return false; 15 | } 16 | else if(dp[r][i]-dp[r-k][i] > good[i]) 17 | return false; 18 | } 19 | return true; 20 | } 21 | 22 | int main() 23 | { 24 | string s, p; 25 | cin >> s >> p; 26 | k = p.length(); 27 | 28 | for(char c : p) 29 | good[c-'a']++; 30 | dp[0][(int)(s[0]-'a')]++; 31 | for(int i=1; i 4) 21 | count += (9 - newStr.indexOf(str.charAt(i))); 22 | else 23 | count += newStr.indexOf(str.charAt(i)); 24 | } 25 | System.out.println(count); 26 | sc.close(); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/روز آزادی بیان در برره/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | class Main { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int k = sc.nextInt(); 10 | 11 | int b = 1, p = 0; 12 | 13 | if (k %2 == 0 ) 14 | System.out.println("Bala Barare"); 15 | else if (k %2 != 0) 16 | System.out.println("Payin Barare"); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رژیم سخت/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Main { 4 | 5 | static Scanner sc; 6 | 7 | public static void main(String[]args){ 8 | sc = new Scanner(System.in); 9 | String string = sc.nextLine(); 10 | 11 | int r = 0; 12 | int g = 0; 13 | int y = 0; 14 | 15 | for (char ch : string.toCharArray()) { 16 | if(String.valueOf(ch).equals("R") || String.valueOf(ch).equals("r")) 17 | r++; 18 | else if(String.valueOf(ch).equals("G") || String.valueOf(ch).equals("g")) 19 | g++; 20 | else if(String.valueOf(ch).equals("Y") || String.valueOf(ch).equals("y")) 21 | y++; 22 | } 23 | 24 | if( (y == string.length() || r == string.length()) || (r >= 3) || (r >= 2 && y >= 2) || (y==4 && r==1) ) { 25 | System.out.println("nakhor lite"); 26 | } else { 27 | System.out.println("rahat baash"); 28 | } 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رژیم سخت/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main2{ 4 | 5 | public static void main(String[] args){ 6 | Scanner sc = new Scanner(System.in); 7 | String str = sc.nextLine(); 8 | char [] string_chars = new char[5]; 9 | 10 | for(int i=0;i<5;i++){ 11 | string_chars[i] = str.charAt(i); 12 | } 13 | 14 | int countR=0,countY=0,countG=0; 15 | 16 | for(int i=0;i=3) | (countR>=2 & countY>=2) | (countG==0) ){ 26 | System.out.println("nakhor lite"); 27 | }else 28 | System.out.println("rahat baash"); 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رژیم سخت/main.cpp: -------------------------------------------------------------------------------- 1 | #include "iostream" 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | char ch[6]; 9 | int r = 0; 10 | int g = 0; 11 | int y = 0; 12 | 13 | cin >> ch; 14 | 15 | for(int i=0; i<=4;i++) 16 | { 17 | if((int) ch[i] == (int) 'R' || (int) ch[i] == (int) 'r') 18 | r++; 19 | else if((int) ch[i] == (int) 'G' || (int) ch[i] == (int) 'g') 20 | g++; 21 | else if((int) ch[i] == (int) 'Y' || (int) ch[i] == (int) 'y') 22 | y++; 23 | } 24 | 25 | if( (r == 5 || y == 5) || ( r >= 3 ) || ( r >=2 && y >= 2) || (r == 1 && y == 4) ) 26 | cout << "nakhor lite" << endl; 27 | else 28 | cout << "rahat baash" << endl; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رژیم سخت/practice.py: -------------------------------------------------------------------------------- 1 | str = input() 2 | if str.count('R') >=3: 3 | print("nakhor lite") 4 | elif str.count('R') >=2 & str.count('Y') >=2: 5 | print("nakhor lite") 6 | elif str.count('G') == 0: 7 | print("nakhor lite") 8 | else: 9 | print('rahat baash') -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رییس و کارخانه شکلات‌سازی/Main5.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | /** 5 | * Created by AMK on 8/1/2019. 6 | * Life is nice :) 7 | * Enjoy coding :D 8 | */ 9 | public class Main5 { 10 | private static int INF = 999999999; 11 | 12 | public static void main(String[] args) { 13 | Scanner scanner = new Scanner(System.in); 14 | int n = scanner.nextInt(); 15 | ArrayList arrayList[] = new ArrayList[n]; 16 | for (int i = 0; i < n; i++) { 17 | arrayList[i] = new ArrayList<>(); 18 | } 19 | for (int i = 1; i < n; i++) { 20 | int x = scanner.nextInt(); 21 | arrayList[x - 1].add(i); 22 | } 23 | System.out.println(Calc(arrayList, 0)); 24 | 25 | } 26 | 27 | private static value Calc(ArrayList[] arrayList, int i) { 28 | int pen = 1; 29 | int members = arrayList[i].size(); 30 | if (arrayList[i].size() == 0) { 31 | return new value(pen,0); 32 | } 33 | for (int j = 0; j < arrayList[i].size(); j++) { 34 | value val = Calc(arrayList, arrayList[i].get(j)); 35 | pen += val.pen; 36 | members += val.members; 37 | } 38 | return new value(pen + members,members); 39 | } 40 | 41 | static class value { 42 | int pen,members; 43 | 44 | public value(int pen, int members) { 45 | this.pen = pen; 46 | this.members = members; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return pen + ""; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/رییس و کارخانه شکلات‌سازی/answer.py: -------------------------------------------------------------------------------- 1 | class tree: 2 | def __init__(self, father, jarime, index): 3 | self.index = index 4 | self.children = [] 5 | self.father = father 6 | self.jarime = jarime 7 | 8 | nodes = [] 9 | 10 | def findjarime(index): 11 | global nodes 12 | jar = 0 13 | childs = nodes[index].children 14 | count = 0 15 | for child in childs: 16 | res = findjarime(child.index) 17 | jar += res[0] 18 | count += res[1] 19 | jar+= count 20 | jar += 1 21 | count += 1 22 | return jar,count 23 | 24 | n = int(input()) 25 | 26 | line = input() 27 | farman = line.split(" ") 28 | 29 | 30 | for i in range(n): 31 | nodes.append(tree(None, None, i)) 32 | 33 | for i in range(len(farman)): 34 | nodes[i+1].father = nodes[int(farman[i])-1] 35 | nodes[int(farman[i])-1].children.append(nodes[i+1]) 36 | 37 | boss = None 38 | for i in range(n): 39 | if(nodes[i].father == None): 40 | boss = i 41 | break 42 | 43 | print(findjarime(boss)[0]) 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/زرد/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static Scanner sc = new Scanner(System.in); 5 | public static void main(String[] args) { 6 | int num = sc.nextInt(); 7 | System.out.print("W"); 8 | for (int i=1; i<=num; i++) 9 | System.out.print("o"); 10 | System.out.print("w!"); 11 | } 12 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/زوج سرمایه دار/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int[] a = new int[n]; 12 | long countPos = 0, countNeq = 0, countZero = 0; 13 | 14 | for (int i = 0; i < n; i++) { 15 | a[i] = sc.nextInt(); 16 | if (a[i] > 0) 17 | countPos++; 18 | else if (a[i] < 0) 19 | countNeq++; 20 | else 21 | countZero++; 22 | } 23 | 24 | if (countNeq == 0) 25 | System.out.println(0); 26 | else { 27 | System.out.println((countNeq*n) - countNeq); 28 | 29 | } 30 | 31 | sc.close(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/زیررشته مشترک/temp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Spyder Editor 4 | 5 | This is a temporary script file. 6 | """ 7 | 8 | n = int(input()) 9 | a = [] 10 | minSize=10000 11 | for i in range(n): 12 | s = input() 13 | a.append(s) 14 | if len(s)= start and rtime <= end: 15 | return False if order == "closed" else True 16 | for start, end, order in store: 17 | if rtime >= start and rtime <= end: 18 | return False if order == "closed" else True 19 | for start, end, order in tenant: 20 | if rtime >= start and rtime <= end: 21 | return False if order == "closed" else True 22 | for day, start, end in week: 23 | if rtime.strftime("%A") == day: 24 | start = [int(x) for x in start.split(':')] 25 | end = [int(x) for x in end.split(':')] 26 | if rtime.hour > start[0] or (rtime.hour == start[0] and rtime.minute >= start[1]): 27 | if rtime.hour < end[0] or (rtime.hour == end[0] and rtime.minute <= end[1]): 28 | return True 29 | return False 30 | 31 | 32 | for i in range(n): 33 | day, start, end = map(str, input().split()) 34 | week.append((day, start, end)) 35 | 36 | 37 | 38 | for i in range(m): 39 | dast, start, end, order = map(str, input().split()) 40 | start = dt.strptime(start , tform) 41 | end = dt.strptime(end , tform) 42 | if dast == "Station": 43 | station.append((start, end, order)) 44 | elif dast == "Store": 45 | store.append((start, end, order)) 46 | elif dast == "Tenant": 47 | store.append((start, end, order)) 48 | 49 | for i in range(q): 50 | rtime = input() 51 | if isOpen(rtime): 52 | print("true") 53 | else: 54 | print("false") 55 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سریال/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | int main() { 6 | int n,k; 7 | cin >> n >>k; 8 | int* roz; 9 | roz=new int[n]; 10 | for(int i=0;i> roz[i]; 12 | int mota=0; 13 | int mota2=0; 14 | for(int i=1;imota2) 21 | mota2=mota; 22 | mota=0; 23 | } 24 | 25 | } 26 | if(k<=n-mota2-1) 27 | cout << mota2+k+1; 28 | else 29 | cout << n; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سریال/temp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Spyder Editor 4 | 5 | This is a temporary script file. 6 | """ 7 | 8 | n, k = [int(x) for x in input().split()] 9 | days = [int(x) for x in input().split()] 10 | selected_max_len = 1 11 | max_len = 1 12 | counter = 0 13 | while counter < n-1: 14 | if days[counter+1] == days[counter] + 1: 15 | max_len += 1 16 | else: 17 | selected_max_len = max_len if max_len > selected_max_len else selected_max_len 18 | max_len = 1 19 | counter += 1 20 | print(selected_max_len + k if selected_max_len + k < n else n) 21 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سطح اعتیاد/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = INT32_MIN; 10 | using namespace std; 11 | 12 | void fast() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(NULL); cout.tie(NULL); 15 | } 16 | 17 | 18 | int main() { 19 | fast(); 20 | long n; 21 | cin>>n; 22 | vector vv; 23 | while(n--){ 24 | long x; 25 | cin>>x; 26 | vv.push_back(x); 27 | } 28 | long ans = vv[0]; 29 | for(unsigned int i = 1; i < vv.size(); i++){ 30 | ans = __gcd(vv[i],ans); 31 | } 32 | long sum = 0; 33 | for(unsigned int i = 0; i < vv.size (); i++){ 34 | sum += vv[i] / ans; 35 | } 36 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int v,v2; 8 | cin >> v; 9 | double cube = cbrt(v);; 10 | int k = floor(cube); 11 | int b = ceil(cube); 12 | int aval1,aval2; 13 | for(b; b<=v; b++) 14 | { 15 | if(v%b == 0) 16 | { 17 | aval1 = b; 18 | break; 19 | } 20 | } 21 | 22 | for(k; k>=1; k--) 23 | { 24 | if(v%k == 0) 25 | { 26 | aval2 = k; 27 | break; 28 | } 29 | } 30 | v2 = v/aval2; 31 | v /= aval1; 32 | int dovom1, dovom2; 33 | double squre = sqrt(v); 34 | k = floor(squre); 35 | b = ceil(squre); 36 | for(b; b<=v; b++) 37 | { 38 | if(v%b == 0) 39 | { 40 | dovom1 = b; 41 | break; 42 | } 43 | } 44 | 45 | for(k; k>=1; k--) 46 | { 47 | if(v%k == 0) 48 | { 49 | dovom2 = k; 50 | break; 51 | } 52 | } 53 | 54 | squre = sqrt(v2); 55 | k = floor(squre); 56 | b = ceil(squre); 57 | int dovom3, dovom4; 58 | 59 | for(b; b<=v2; b++) 60 | { 61 | if(v2%b == 0) 62 | { 63 | dovom3 = b; 64 | break; 65 | } 66 | } 67 | 68 | for(k; k>=1; k--) 69 | { 70 | if(v2%k == 0) 71 | { 72 | dovom4 = k; 73 | break; 74 | } 75 | } 76 | 77 | 78 | int sevom1 = v/dovom1; 79 | int sevom2 = v/dovom2; 80 | int sevom3 = v2/dovom3; 81 | int sevom4 = v2/dovom4; 82 | 83 | int mini = min((aval1*dovom1*2) + (aval1*sevom1*2) + (dovom1*sevom1*2) , (aval1*dovom2*2) + (aval1*sevom2*2) + (dovom2*sevom2*2)); 84 | int mini2 = min((aval2*dovom3*2) + (aval2*sevom3*2) + (dovom3*sevom3*2) , (aval2*dovom4*2) + (aval2*sevom4*2) + (dovom4*sevom4*2)); 85 | int mini3 = min(mini,mini2); 86 | cout << mini3; 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سلام سلام خداحافظ/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | String n = sc.nextLine(); 9 | int nn = Integer.parseInt(n); 10 | String myInput = sc.nextLine(); 11 | String[] splited = myInput.split("\\s+"); 12 | 13 | if(nn < 0 || nn > 50) 14 | return; 15 | 16 | for (int i = 2; i<=nn; i++) { 17 | for (int j = i - 1; j>=1; j--) { 18 | System.out.println(splited[i - 1] + ": salam " + splited[j - 1] + "!"); 19 | } 20 | } 21 | 22 | for (int i = 1; i<=nn; i++) { 23 | System.out.println(splited[i - 1] + ": khodafez bacheha!"); 24 | for(int j = i + 1; j <= nn; j++) { 25 | System.out.println(splited[j - 1] + ": khodafez " + splited[i - 1] + "!"); 26 | } 27 | } 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سوال اول/Main.java: -------------------------------------------------------------------------------- 1 | package com.example.idea; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | String one = sc.nextLine(); 11 | String two = sc.nextLine(); 12 | 13 | int repeat = StringInString(one,two); 14 | System.out.println(repeat); 15 | sc.close(); 16 | } 17 | 18 | public static int StringInString(String one, String two) { 19 | int count =0; 20 | int lastIndex=0; 21 | if( one == null || two == null || one.equals("") || two.equals("")) 22 | return 0; 23 | while (lastIndex !=-1){ 24 | lastIndex = one.indexOf(two, lastIndex); 25 | 26 | if (lastIndex != -1) { 27 | count++; 28 | lastIndex++; 29 | } 30 | } 31 | return count; 32 | } 33 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سوراخ موش/SorakhMoosh.py: -------------------------------------------------------------------------------- 1 | m , h = input().split() 2 | m = int(m) 3 | h = int(h) 4 | 5 | if m == h: 6 | print("Saal Noo Mobarak!") 7 | elif m < h: 8 | for i in range(h-m): 9 | print("R",end='') 10 | else: 11 | for i in range(m-h): 12 | print("L",end='') 13 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سپیده/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt() , m = sc.nextInt(), sum=0; 8 | sum = (n+m - 1) / m; 9 | System.out.println(sum); 10 | sc.close(); 11 | } 12 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/سیگماگیر/Main.java: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | import java.util.Scanner; 36 | import java.lang.Math.*; 37 | 38 | public class Main { 39 | 40 | public static Scanner sc; 41 | 42 | 43 | public static void main(String[] args) { 44 | sc = new Scanner(System.in); 45 | int n = sc.nextInt(); 46 | int m = sc.nextInt(); 47 | int sum = 0; 48 | int temp = 0; 49 | 50 | if(n < 0 ||m > 10) 51 | return; 52 | 53 | for (int i = -10; i <= m; i++) { 54 | for (int j = 1; j <= n; j++) { 55 | if(j == 0) 56 | continue; 57 | 58 | temp = (int)java.lang.Math.pow(i + j, 3); 59 | sum += temp / (int)java.lang.Math.pow(j, 2); 60 | } 61 | } 62 | 63 | System.out.println(sum); 64 | 65 | 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/شارژ موبایل/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main{ 4 | 5 | public static void main(String[] args){ 6 | Scanner sc = new Scanner(System.in); 7 | int k = sc.nextInt(); 8 | int i=0,sum=0; 9 | 10 | while((i+1)<=k){ 11 | sum+=i+1; 12 | i++; 13 | } 14 | System.out.println(sum); 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/شطرنج حرفه‌ای/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | 4 | class Test { 5 | 6 | public static void main(String[] args){ 7 | Scanner sc = new Scanner(System.in); 8 | int [] chess = {1,1,2,2,2,8}; 9 | int [] p = new int[6]; 10 | 11 | for(int i=0;i<6;i++){ 12 | p[i] = sc.nextInt(); 13 | } 14 | 15 | for(int i=0;i<6;i++){ 16 | if(chess[i] == p[i]){ 17 | p[i] = 0; 18 | System.out.print(p[i]+" "); 19 | }else{ 20 | p[i] = chess[i] - p[i]; 21 | System.out.print(p[i]+" "); 22 | } 23 | } 24 | 25 | 26 | } 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/شطرنج حرفه‌ای/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int shah[2] = {1, 0}; 8 | int vazir[2] = {1 , 0}; 9 | int rokh[2] = {2, 0}; 10 | int fil[2] = {2 , 0}; 11 | int asb[2] = {2, 0}; 12 | int sarbaz[2] = {8 , 0}; 13 | 14 | cin >> shah[1] >> vazir[1] >> rokh[1] >> fil[1] >> asb[1] >> sarbaz[1]; 15 | 16 | cout << shah[0]-shah[1] << " " << vazir[0]-vazir[1] << " " << rokh[0]-rokh[1] << " " << fil[0]-fil[1] << " " << asb[0]-asb[1] << " " << sarbaz[0]-sarbaz[1]; 17 | 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/شظرنج میوه ای/solution.py: -------------------------------------------------------------------------------- 1 | def fruits(tuple_of_fruits): 2 | l = [] 3 | for i in tuple_of_fruits: 4 | if ((i['shape'] == 'sphere') and (300 <= i['mass'] <= 600) and 5 | (100 <= i['volume'] <= 500)): 6 | l.append(i['name']) 7 | dic = {} 8 | for items in l: 9 | dic.update({items: l.count(items)}) 10 | 11 | return dic 12 | 13 | 14 | output = fruits(( 15 | {'name': 'apple', 'shape': 'sphere', 'mass': 350, 'volume': 120}, 16 | {'name': 'mango', 'shape': 'square', 'mass': 150, 'volume': 120}, 17 | {'name': 'lemon', 'shape': 'sphere', 'mass': 300, 'volume': 100}, 18 | {'name': 'apple', 'shape': 'sphere', 'mass': 500, 'volume': 250})) 19 | 20 | print(output) 21 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/صبا و سوال ساده/Main.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | float n = sc.nextFloat(); 9 | float k = sc.nextFloat(); 10 | for (int i = 0; i < k; i++) { 11 | n = (n/2); 12 | 13 | } 14 | System.out.println((int) Math.floor(n)); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/صدگان خسته/Main2.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main2 { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int num1 = sc.nextInt(); 12 | int num2 = sc.nextInt(); 13 | 14 | reverse(num1,num2); 15 | 16 | 17 | } 18 | 19 | private static void reverse(int num1, int num2){ 20 | 21 | int b=0,c=0; 22 | int a = num1; 23 | int d = num2; 24 | while (a!=0){ 25 | b = b*10 + a%10; 26 | a/=10; 27 | } 28 | 29 | while (d!=0){ 30 | c = c*10 + d%10; 31 | d/=10; 32 | } 33 | 34 | if (b < c) 35 | System.out.println(num1+" "+"<"+" "+num2); 36 | else if (c < b) 37 | System.out.println(num2+" "+"<"+" "+num1); 38 | else 39 | System.out.println(num1+" "+"="+" "+num2); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/عدد خود مغلوب/Khod Maqlob.py: -------------------------------------------------------------------------------- 1 | n = input() 2 | 3 | if n[::-1] == n: 4 | print("YES") 5 | else: 6 | print("NO") 7 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/قرارمون یادت نره/answer.py: -------------------------------------------------------------------------------- 1 | import time 2 | from datetime import timedelta, datetime 3 | p, m = map(int, input().split()) 4 | 5 | karmand = {} 6 | 7 | def isOk(start, end): 8 | for i in range(start, end+1): 9 | for k in ks: 10 | if not karmand[k][i]: 11 | return False 12 | for i in range(start, end+1): 13 | for k in ks: 14 | karmand[k][i] = False 15 | return True 16 | 17 | for i in range(p): 18 | name, e, start, end = map(str, input().split()) 19 | ee = [int(x) for x in e[1:].split(':')] 20 | start = datetime.strptime(start, '%H:%M') 21 | end = datetime.strptime(end, '%H:%M') 22 | td = timedelta(hours = ee[0], minutes = ee[1]) 23 | 24 | if e[0] == '+': 25 | start = start - td 26 | end = end - td 27 | else: 28 | start = start + td 29 | end = end + td 30 | 31 | karmand[name] = [False for j in range(1440)] 32 | for j in range(start.hour*60+start.minute, end.hour*60+end.minute): 33 | karmand[name][j] = True 34 | 35 | 36 | for i in range(m): 37 | c, t = map(int, input().split()) 38 | 39 | ks = input().split() 40 | 41 | oked = False 42 | for j in range(1440-t+1): 43 | res = isOk(j, j+t-1) 44 | if res: 45 | hh, mm = str(j // 60), str(j % 60) 46 | if len(hh) == 1: 47 | hh = '0' + hh 48 | if len(mm) == 1: 49 | mm = '0' + mm 50 | print(hh + ":" + mm) 51 | oked = True 52 | break 53 | 54 | 55 | if not oked: 56 | print("N/A") 57 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/قناد ناشی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | #define ll long long 12 | 13 | bool isPrime(int num) 14 | { 15 | if(num == 1) 16 | return false; 17 | for(int i=2; i<=sqrt(num); i++) 18 | { 19 | if(num % i == 0) 20 | return false; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | int main() 27 | { 28 | int k; 29 | cin >> k; 30 | 31 | ll hasel = 1; 32 | for(int i=1; i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | for(int i=0; i max_color){ 17 | max_color = color[i]; 18 | } 19 | } 20 | 21 | int answer = -1; 22 | for (int i = 1; i <= max_color; i++) { 23 | if (counter[i] > 0) 24 | if (answer == -1 || counter[answer] > counter[i] || (counter[answer] == counter[i] && i < answer) ) 25 | answer = i; 26 | } 27 | 28 | 29 | 30 | System.out.println(answer); 31 | 32 | 33 | 34 | sc.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مجید، میلاد، رشته‌سازی/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 31 | 31 32 | 32 33 | 33 34 | 34 35 | 35 36 | 36 37 | 37 38 | import java.util.Scanner; 39 | 40 | public class Main { 41 | 42 | public static void main(String[] args) { 43 | Scanner sc = new Scanner(System.in); 44 | 45 | // First String To run in programm 46 | String firstString = "1"; 47 | String lastString = "1"; 48 | 49 | // Give Input 50 | String input = sc.nextLine(); 51 | String[] tempInput = input.split(" "); 52 | int L = Integer.parseInt(tempInput[0]); 53 | int R = Integer.parseInt(tempInput[1]); 54 | 55 | String temp; 56 | 57 | for (int i = 0; firstString.length() <= R + 1; i++) { 58 | 59 | if(i == 0) { 60 | firstString = "10"; 61 | lastString = "01"; 62 | } 63 | 64 | temp = lastString + firstString; 65 | firstString += lastString; 66 | lastString = temp; 67 | 68 | } 69 | 70 | System.out.println(firstString.substring(L - 1,R)); 71 | 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مربّاها و قفسه‌بندی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | /** 5 | * Created by AMK on 8/2/2019. 6 | * Life is nice :) 7 | * Enjoy coding :D 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | Scanner scanner = new Scanner(System.in); 12 | int n = scanner.nextInt(); 13 | ArrayList arrayList = new ArrayList<>(); 14 | for (int i = 0; i < n; i++) { 15 | int a = scanner.nextInt(); 16 | int b = scanner.nextInt(); 17 | Member member = new Member(a,b); 18 | arrayList.add(member); 19 | } 20 | int ans = n + 1; 21 | for (int i = 0; i < arrayList.size(); i++) { 22 | for (int j = i + 1; j < arrayList.size(); j++) { 23 | if (arrayList.get(i).a != arrayList.get(j).a){ 24 | ans++; 25 | } 26 | } 27 | } 28 | System.out.println(ans); 29 | } 30 | static class Member{ 31 | int a,b; 32 | 33 | public Member(int a, int b) { 34 | this.a = a; 35 | this.b = b; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مرتب سازی رشته ها/temp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Spyder Editor 4 | 5 | This is a temporary script file. 6 | """ 7 | 8 | p = input().split()[:-1] 9 | n = len(p) 10 | res = [] 11 | for i in range(n): 12 | k = min(x for x in range(n) if p[x] != 'ISSA') 13 | for j in range(0,n): 14 | if p[j]=='ISSA': 15 | continue 16 | if p[k][0:1].lower() > p[j][0:1].lower(): 17 | k = j 18 | elif p[k][0:1].lower() == p[j][0:1].lower(): 19 | if p[k][0:1] > p[j][0:1]: 20 | k = j 21 | elif p[k][0:1] == p[j][0:1]: 22 | if p[k][0:2].lower() > p[j][0:2].lower(): 23 | k = j 24 | elif p[k][0:2].lower() == p[j][0:2].lower(): 25 | if p[k][0:2] > p[j][0:2]: 26 | k = j 27 | res.append(p[k]) 28 | p[k]='ISSA' 29 | print(' '.join(res)) 30 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مسئله ی آب/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | long a = sc.nextLong() , b = sc.nextLong(), c=sc.nextLong() , d = sc.nextLong() , e =sc.nextLong() , f=sc.nextLong(); 8 | 9 | if ((a >= d) && (b>=e)) 10 | System.out.println("zende mimuni"); 11 | else if (a>=e && b>=d) 12 | System.out.println("zende mimuni"); 13 | else if (a>=f && b>=e) 14 | System.out.println("zende mimuni"); 15 | else if (a>=e && b>=f) 16 | System.out.println("zende mimuni"); 17 | else if (a>=f && b>=d) 18 | System.out.println("zende mimuni"); 19 | else if (a>=d && b>=f) 20 | System.out.println("zende mimuni"); 21 | else 22 | System.out.println("dari mimiri"); 23 | sc.close(); 24 | } 25 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مسابقه آسان/مسابقه‌ی آسان.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | n = input().split(' ') 4 | for i in range(len(n)): 5 | n[i] = int(n[i]) 6 | fact = math.factorial(n[0]) 7 | fact = str(fact) 8 | ls = [] 9 | for i in fact: 10 | ls.append(i) 11 | print(ls.count(str(n[1]))) 12 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مساحت/solution.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | def get_func(ls): 5 | list = [] 6 | for item in ls: 7 | if item == "square": 8 | def f(x): 9 | return x * x 10 | 11 | list.append(f) 12 | elif item == "circle": 13 | def f(x): 14 | return math.pi * x * x 15 | 16 | list.append(f) 17 | elif item == "rectangle": 18 | def f(x, y): 19 | return x * y 20 | 21 | list.append(f) 22 | elif item == "triangle": 23 | def f(x, y): 24 | return x * y / 2 25 | 26 | list.append(f) 27 | 28 | return list 29 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مساله هالت/answer.py: -------------------------------------------------------------------------------- 1 | x = int(input()) 2 | list1 = [] 3 | 4 | for i in range((int)(x)): 5 | list1.append(input()) 6 | 7 | 8 | 9 | variables = {} 10 | outputs = [] 11 | line = 0 12 | tekrar = [] 13 | for i in range(x): 14 | tekrar.append(0) 15 | flag = False 16 | while(True): 17 | aKhat = list1[line].split(" ") 18 | tekrar[line] += 1 19 | if(tekrar[line] > 1): 20 | flag = True 21 | print(-1) 22 | break 23 | if(aKhat[0] == "assign"): 24 | aval = aKhat[3] 25 | dovom = aKhat[5] 26 | if(not aval.isdigit()): 27 | if(not aval in variables): 28 | variables[aval] = 0 29 | aval = variables[aval] 30 | if(not dovom.isdigit()): 31 | if(not dovom in variables): 32 | variables[dovom] = 0 33 | dovom = variables[dovom] 34 | variables[aKhat[1]] = (int(aval) + int(dovom)) % 1000000007 35 | elif(aKhat[0] == "cout"): 36 | adad = aKhat[1] 37 | if(not adad.isdigit()): 38 | if(not adad in variables): 39 | variables[adad] = 0 40 | adad = variables[adad] 41 | outputs.append(adad) 42 | 43 | if(aKhat[0] == "goto"): #elif to if 44 | line = int(aKhat[1]) -1 45 | else: #added7 46 | line += 1 #added 47 | if(line >= x):#added 48 | break #added 49 | 50 | if(not flag): 51 | for i in outputs: 52 | print(i) 53 | 54 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مستطیل بد/Test4.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test4 { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | long ans = 0; 9 | for (int i = 1; i <= n/3; i++) { 10 | ans = ans + ((n-3*i)/2) - Math.max(0 , (n/2) - (2*i)+1) + 1; 11 | } 12 | System.out.println(ans); 13 | 14 | sc.close(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مستطیل کادویی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const char nl = '\n'; 5 | #define IN(A, B, C) assert( B <= A && A <= C) 6 | #define PI 3.1415926535897932384626433832795 7 | #define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++) 8 | #define present(c,x) ((c).find(x) != (c).end()) 9 | #define cpresent(c,x) (find(all(c),x) != (c).end()) 10 | #define sz(a) int((a).size()) 11 | #define acc ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); 12 | #define ll long long 13 | #define ld long double 14 | #define inf 2147483647 15 | #define infll 9223372036854775807 16 | 17 | void solve() 18 | { 19 | 20 | } 21 | 22 | int main() 23 | { 24 | #ifndef Test 25 | acc; 26 | #endif 27 | 28 | int m,n; 29 | cin>>n>>m; 30 | string matrix[n]; 31 | for(int i=0; i> matrix[i]; 33 | bitset<2500> row[n], res; 34 | for(int i=0 ;i 0) res = row[j]^row[i-1]; 48 | else res = row[j]; 49 | f = res.count(), z = m-f; 50 | ans += f*(f-1)/2 + (z+1)*(z)/2; 51 | } 52 | } 53 | 54 | cout << ans << endl; 55 | #ifdef Test 56 | cout << endl; system("pause"); 57 | #endif 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مشق امشب باقر/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | int c = sc.nextInt(); 13 | 14 | if ( a + b + c != 180 ) 15 | System.out.println("No"); 16 | else if ( a == 0 || b == 0 || c == 0 ) 17 | System.out.println("No"); 18 | else if( (a + b > c) && (a + c > b) && (b + c > a) ) 19 | System.out.println("Yes"); 20 | else 21 | System.out.println("No"); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مشق امشب باقر/Triangle.py: -------------------------------------------------------------------------------- 1 | li = list(map(int,input().split(' '))) 2 | if sum(li) == 180 and li[1]!=0 and li[2]!=0 and li[0]!=0 : 3 | print('Yes') 4 | else: 5 | print('No') -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مشق امشب باقر/practice.py: -------------------------------------------------------------------------------- 1 | a, b, c = input().split() 2 | a = int(a) 3 | b = int(b) 4 | c = int(c) 5 | if (a+b+c == 180) and a!=0 and b!=0 and c!=0: 6 | print('Yes') 7 | else: 8 | print('No') -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مصاحبه با وزیران/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | bool sortbysec(const pair &a, const pair &b) 5 | { 6 | return (a.second < b.second); 7 | } 8 | 9 | ll choose(ll n) 10 | { 11 | return (n*n + n)/2; 12 | } 13 | 14 | int main() 15 | { 16 | int n, m; 17 | cin >> n >> m; 18 | pair baze[n-1]; 19 | for(int i=0; i> baze[i].first >> baze[i].second; 20 | pair com = make_pair(max_element(baze, baze+n-1)->first, min_element(baze, baze+n-1, sortbysec)->second); 21 | ll ans = choose(m) - choose(com.first-1) - choose(m-com.second); 22 | cout << ans << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مقایسه گر/solution.py: -------------------------------------------------------------------------------- 1 | def compare(string1, string2): 2 | while (len(string1) >=1 and len(string2) >=1): 3 | if (string1[0] > string2[0]): 4 | string2 = string2[1:] 5 | 6 | string2 = string2[::-1] 7 | string1 = string1[::-1] 8 | elif (string2[0] > string1[0]): 9 | string1 = string1[1:] 10 | 11 | string2 = string2[::-1] 12 | string1 = string1[::-1] 13 | else: 14 | string2 = string2[1:] 15 | string1 = string1[1:] 16 | 17 | string2 = string2[::-1] 18 | string1 = string1[::-1] 19 | 20 | if (len(string1) == 0 and len(string2) == 0): 21 | return "Both strings are empty!" 22 | elif (len(string1) == 0): 23 | return string2[::-1] 24 | else: 25 | return string1[::-1] -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مقسوم علیه های دردسرساز/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | int num = sc.nextInt(); 9 | 10 | int count=0,sum=0; 11 | 12 | for (int i = 1; i <= num; i++) { 13 | for (int j=1;j<=i;j++) { 14 | if (i % j == 0) { 15 | count++; 16 | sum += j; 17 | } 18 | } 19 | } 20 | System.out.print(count); 21 | System.out.println(" "+sum); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/مُجَزا/solution.py: -------------------------------------------------------------------------------- 1 | def separator(ls): 2 | odd_l = [] 3 | even_l = [] 4 | for i in ls: 5 | if i % 2 == 0: 6 | even_l.append(i) 7 | else: 8 | odd_l.append(i) 9 | 10 | t = (even_l, odd_l) 11 | return t -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/نرمش جدول/Main3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * Created by AMK on 8/12/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main3 { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | int n = scanner.nextInt(); 12 | int arr[][] = new int[n][n]; 13 | for (int i = 0; i < n; i++) { 14 | String line = scanner.next(); 15 | for (int j = 0; j < line.length(); j++) { 16 | arr[i][j] = line.charAt(j) == 'W' ? 0 : 1; 17 | } 18 | } 19 | int q = scanner.nextInt(); 20 | for (int i = 0; i < q; i++) { 21 | String s = scanner.next(); 22 | int arr2[][] = new int[n][n]; 23 | if (s.equals("90")){ 24 | for (int j = 0; j < n; j++) { 25 | for (int k = 0; k < n; k++) { 26 | arr2[k][n - j - 1] = arr[j][k]; 27 | } 28 | } 29 | arr = arr2; 30 | }else if (s.equals("V")){ 31 | for (int j = 0; j < arr.length; j++) { 32 | for (int k = 0; k < n / 2; k++) { 33 | int temp = arr[j][n - k - 1]; 34 | arr[j][n - k - 1] = arr[j][k]; 35 | arr[j][k] = temp; 36 | } 37 | } 38 | }else{ 39 | for (int j = 0; j < n / 2; j++) { 40 | for (int k = 0; k < n; k++) { 41 | int temp = arr[n - j - 1][k]; 42 | arr[n - j - 1][k] = arr[j][k]; 43 | arr[j][k] = temp; 44 | } 45 | } 46 | } 47 | } 48 | for (int i = 0; i < n; i++) { 49 | for (int j = 0; j < n; j++) { 50 | System.out.print(arr[i][j] == 1 ? "B" : "W"); 51 | } 52 | System.out.println(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/نظریه ریسمان/Risman.py: -------------------------------------------------------------------------------- 1 | s1 = input() 2 | s2 = input() 3 | 4 | print(s2.count(s1)) 5 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/نعلم کو؟!/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, m; 7 | cin >> n >> m; 8 | string mazrae[n]; 9 | 10 | for(int i=0; i> mazrae[i]; 12 | 13 | int t = 0, nn, mm; 14 | int circle[8][2] = {{0,0}, {0,1}, {0,2}, {1,2}, {2, 2}, {2, 1}, {2, 0}, {1, 0}}; 15 | 16 | for(int i=0; i= 6) 28 | t++; 29 | } 30 | else 31 | motavali = 0; 32 | } 33 | } 34 | } 35 | 36 | cout << t << endl; 37 | system("pause"); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/نیمبو-دومینوها/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String args[]) { 7 | Scanner scanner = new Scanner(System.in); 8 | int n = scanner.nextInt(); 9 | int m = scanner.nextInt(); 10 | char[][] chars = new char[n][m]; 11 | int ans = 0; 12 | int arr[] = new int[m]; 13 | for (int i = 0; i < n; i++) { 14 | chars[i] = scanner.next().toCharArray(); 15 | int flag = 0; 16 | for (int j = 0; j < m; j++) {; 17 | if (chars[i][j] == '|') { 18 | flag = 1; 19 | } else { 20 | if (flag == 1) { 21 | flag = 0; 22 | ans++; 23 | } 24 | } 25 | if (chars[i][j] == '-') { 26 | if (arr[j] == 0) { 27 | ans++; 28 | arr[j] = 1; 29 | } 30 | } else { 31 | arr[j] = 0; 32 | } 33 | } 34 | if (flag == 1) { 35 | ans++; 36 | } 37 | } 38 | System.out.println(ans); 39 | } 40 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/نیمبو-صفا/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String args[]) { 7 | Scanner scanner = new Scanner(System.in); 8 | int n = scanner.nextInt(); 9 | int q = scanner.nextInt(); 10 | int arr2[] = new int[n + 1]; 11 | int arr[] = new int[n + 1]; 12 | ArrayList arrayList = new ArrayList<>(); 13 | arrayList.add((long) 0); 14 | for (int i = 0; i < q; i++) { 15 | int command = scanner.nextInt(); 16 | if (command == 1) { 17 | int number = scanner.nextInt(); 18 | arrayList.add(arrayList.get(arrayList.size() - 1) + number); 19 | } else { 20 | int I = scanner.nextInt(); 21 | int j = scanner.nextInt(); 22 | arr2[I] += j; 23 | System.out.println(arrayList.get(arr2[I]) - arrayList.get(arr[I])); 24 | arr[I] += j; 25 | } 26 | } 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/همایش زندگی بهتر/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class Test { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int r = sc.nextInt() , c = sc.nextInt(); 9 | int [] a = {0,10,9,8,7,6,5,4,3,2,1}; 10 | int [] b = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; 11 | int [] rb = {0,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; 12 | 13 | 14 | if (c >=1 && c<=10){ 15 | System.out.println("Right "+a[r]+" "+b[c]); 16 | 17 | } 18 | else 19 | System.out.println("Left "+a[r]+" "+rb[c]); 20 | sc.close(); 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/هندونه خوری/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | static Scanner scanner; 6 | 7 | public static void main(String[] args) { 8 | int i; 9 | // melon count 10 | scanner = new Scanner(System.in); 11 | int n = Integer.parseInt(scanner.nextLine()); 12 | if(n < 1) 13 | n = 1; 14 | 15 | // weight 16 | String weightText = scanner.nextLine(); 17 | String[] weightTextArray = weightText.split(" "); 18 | 19 | int s1 = 0; 20 | int s2 = 1; 21 | int sNext = 2; 22 | int min = 0; 23 | for (i = 0 ; i < n-1; i++) { 24 | min = Math.min(Integer.parseInt(weightTextArray[s1]), Integer.parseInt(weightTextArray[s2])); 25 | if(min == Integer.parseInt(weightTextArray[s1])) { 26 | weightTextArray[s1] = "-1"; 27 | s1 = sNext; 28 | sNext++; 29 | } 30 | else if(min == Integer.parseInt(weightTextArray[s2])) { 31 | weightTextArray[s2] = "-1"; 32 | s2 = sNext; 33 | sNext++; 34 | } 35 | 36 | } 37 | for (i = 0; i < n; i++) 38 | if(!weightTextArray[i].equals("-1")) { 39 | System.out.println(i+1); 40 | break; 41 | } 42 | 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/هندونه خوری/Main2.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main2 { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int k = n; 10 | int [] w = new int[n+1]; 11 | for (int i = 1; i <=n ; i++) { 12 | w[i] = sc.nextInt(); 13 | } 14 | while (k!=1){ 15 | for (int i = 1; i <=n; i++) { 16 | for (int j = i+1; j <=n; j++) { 17 | if (w[i]!=0) { 18 | if (w[i] < w[j]) { 19 | w[i] = 0; 20 | k--; 21 | } else { 22 | w[j] = 0; 23 | k--; 24 | } 25 | } 26 | } 27 | } 28 | } 29 | for (int i = 1; i < w.length; i++) { 30 | if (w[i]!=0){ 31 | System.out.println(i); 32 | break ; 33 | } 34 | 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/هوهوچیچی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n; 8 | cin >> n; 9 | 10 | for(int i=2; i<=n; i+=2) 11 | { 12 | cout << i << " "; 13 | } 14 | 15 | for(int i=1; i<=n; i+=2) 16 | { 17 | cout << i << " "; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/هیچ‌وقت مغرور نشو!/Main2.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.LinkedList; 3 | import java.util.Queue; 4 | import java.util.Scanner; 5 | 6 | /** 7 | * Created by AMK on 7/30/2019. 8 | * Life is nice :) 9 | * Enjoy coding :D 10 | */ 11 | public class Main2 { 12 | public static void main(String[] args) { 13 | Scanner scanner = new Scanner(System.in); 14 | int n = scanner.nextInt(); 15 | ArrayList arrayList[] = new ArrayList[n + 1]; 16 | for (int i = 0; i <= n; i++) { 17 | arrayList[i] = new ArrayList<>(); 18 | } 19 | for (int i = 0; i < n - 1; i++) { 20 | int x = scanner.nextInt(); 21 | int y = scanner.nextInt(); 22 | arrayList[x].add(y); 23 | arrayList[y].add(x); 24 | } 25 | Queue queue = new LinkedList<>(); 26 | queue.add(1); 27 | int vis[] = new int[n + 1]; 28 | int max = -1; 29 | while (!queue.isEmpty()){ 30 | int x = queue.poll(); 31 | if (vis[x] != 0){ 32 | continue; 33 | } 34 | vis[x] = 1; 35 | int O_o = 0; 36 | for (int i = 0; i < arrayList[x].size(); i++) { 37 | { 38 | O_o++; 39 | queue.add(arrayList[x].get(i)); 40 | } 41 | } 42 | if (O_o > max){ 43 | max = O_o; 44 | } 45 | } 46 | System.out.println(max); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/وزیر و تقسیم زمین/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define watch(x) cout<<(#x)<<" is "<<(x)<<"\n" 4 | #define print(x) cout< vi; 7 | typedef std::vector> vvi; 8 | typedef long long ll; 9 | int INF = 999999; 10 | using namespace std; 11 | 12 | int main(){ 13 | ios_base::sync_with_stdio(false); 14 | int q,x; 15 | cin>>q; 16 | vi vec; 17 | for(int i = 0; i < q; i++){ 18 | cin>>x; 19 | vec.push_back (x); 20 | } 21 | for(int i = q; i > 0;i--){ 22 | if(q % i == 0){ 23 | int sum = 0; 24 | for(int j = 0; j < q / i; j++){ 25 | sum += vec[j]; 26 | } 27 | int j = 0; 28 | for(; j < i; j++){ 29 | int temp = 0; 30 | for(int k = (j) * (q / i); k < (j + 1) * (q / i); k++){ 31 | temp += vec[k]; 32 | } 33 | if(temp != sum){ 34 | break; 35 | } 36 | } 37 | if(j == i){ 38 | cout< 0) { 33 | while (x <= count) { 34 | x *= 2; 35 | } 36 | count -= (x/2); 37 | x =1; 38 | res++; 39 | } 40 | return res; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/پیدایِش/peydayesh.py: -------------------------------------------------------------------------------- 1 | def find(num1, num2, num3): 2 | if num1 != 1 and num2 != 1 and num3 !=1: 3 | return 1 4 | elif num1 !=2 and num2 !=2 and num3 !=2: 5 | return 2 6 | elif num1 !=3 and num2 !=3 and num3 !=3: 7 | return 3 8 | elif num1 !=4 and num2 !=4 and num3 !=4: 9 | return 4 10 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چارپک/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n, m, a[4] = {0}, saf; 8 | cin >> n; 9 | priority_queue pq; 10 | for(int i=0; i> m; 12 | pq.push(m); 13 | } 14 | int t = 0; 15 | while(!pq.empty()) 16 | { 17 | saf = min((int)pq.size(), 4); 18 | for(int i=0; i 0) 22 | pq.push(a[i]); 23 | t++; 24 | } 25 | 26 | cout << t << endl; 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چاپ برعکس/AMK-solution/Main.java: -------------------------------------------------------------------------------- 1 | import java.math.RoundingMode; 2 | import java.text.DecimalFormat; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | static Scanner sc; 7 | public static void main(String[] args) { 8 | sc = new Scanner(System.in); 9 | 10 | int number; 11 | String result = ""; 12 | int counter = 0; 13 | 14 | while (true) { 15 | number = sc.nextInt(); 16 | 17 | if(number == 0) 18 | break; 19 | 20 | if(counter==0) 21 | result = String.valueOf(number); 22 | else 23 | result = String.valueOf(number) + '\n' + result; 24 | 25 | counter++; 26 | } 27 | 28 | System.out.println(result); 29 | } 30 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چاپ برعکس/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Simpler solution 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int [] num = new int[1000]; 11 | int i=0; 12 | 13 | int input; 14 | 15 | while ( (input = sc.nextInt())!=0 ){ 16 | 17 | num[i] = input; 18 | i++; 19 | } 20 | 21 | for (int j=i;j>=0;j--) { 22 | if (num[j]==0) 23 | continue; 24 | System.out.println(num[j]); 25 | 26 | } 27 | 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چاپ لوزی/chapeLoozi.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | for i in range(2*n+1): 4 | if i < (2*n)/2: 5 | star_counter = 2*i+1 6 | space_counter = ((2*n+1) - (2*i+1))//2 7 | row = space_counter*" "+star_counter*"*"+space_counter*" " 8 | print(row) 9 | else: 10 | space_counter = i - int(2*n)//2 11 | star_counter = (2*n+1) - space_counter*2 12 | row = space_counter*" "+star_counter*"*"+space_counter*" " 13 | print(row) 14 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چاپ مربع/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | 12 | for (int i=1; i <= n; i++) 13 | System.out.print("*"); 14 | System.out.println(""); 15 | 16 | if(n - 2 != 0) { 17 | for (int i = 1; i <= n-2; i++) { 18 | System.out.print("*"); 19 | for (int j=1; j <= n-2; j++) { 20 | System.out.print(" "); 21 | } 22 | System.out.println("*"); 23 | } 24 | } 25 | 26 | for (int i=1; i <= n; i++) 27 | System.out.print("*"); 28 | System.out.println(""); 29 | 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چاپ مربع/morabaa.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | for i in range(1,n+1): 4 | if i == 1 or i == n: 5 | for i in range(1,n+1): 6 | print('*',end='') 7 | print() 8 | else: 9 | for i in range(1,n+1,n-2): 10 | print('*',end='') 11 | for j in range(1,(n+1)-2): 12 | print(' ',end='') 13 | print() 14 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چند روزته؟/Main.java: -------------------------------------------------------------------------------- 1 | diff($now); 19 | echo $difference->days; 20 | } 21 | } 22 | 23 | ?> -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چی سون/answer.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | n = int(input()) 4 | l = {} 5 | for i in range(n): 6 | s = input() 7 | if s.startswith("print"): 8 | nameidx = s.split(" ")[1].split("[") 9 | if nameidx[1][:-1].startswith("\""): 10 | print(l[nameidx[0]][nameidx[1][1:-2]]) 11 | else: 12 | print(l[nameidx[0]][int(nameidx[1][:-1])]) 13 | elif s.split(" ")[1] == ':=': 14 | l.update({s.split(" ")[0]: json.loads(s[len(s.split(" ")[0])+4:])}) 15 | 16 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چیدمان/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Test { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); // number of coin columns 8 | int [] coins = new int[n]; 9 | int sum=0, count=0 , avg=0; 10 | for (int i = 0; i < n; i++) { 11 | coins[i] = sc.nextInt(); // the height of columns 12 | } 13 | for (int i = 0; i < coins.length; i++) { 14 | sum += coins[i]; 15 | } 16 | avg = sum/n; 17 | for(int i = 0; i < n; i++){ 18 | if(coins[i] < avg) 19 | while (coins[i] < avg){ 20 | coins[i]+=1; 21 | count++; 22 | } 23 | } 24 | System.out.println(count); 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/چیهمونی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | int times[1440]; 9 | for(int i=0; i<1440; i++) 10 | { 11 | times[i] = 0; 12 | } 13 | 14 | for(int i=0; i> name; 18 | string time; 19 | cin >> time; 20 | int hour, min; 21 | hour = ((time[0]-'0')*10 )+ (time[1]-'0'); 22 | min = ((time[3]-'0')*10 )+ (time[4]-'0'); 23 | int minutes = hour*60 + min; 24 | string raftoamad; 25 | cin >> raftoamad; 26 | if(raftoamad == "+") 27 | { 28 | times[minutes] ++; 29 | } 30 | else 31 | { 32 | times[minutes] --; 33 | } 34 | } 35 | 36 | for(int i=1; i<1440; i++) 37 | { 38 | times[i] += times[i-1]; 39 | } 40 | 41 | int max = -1; 42 | int maxIndex = -1; 43 | for(int i=0; i<1440; i++) 44 | { 45 | if(times[i] > max) 46 | { 47 | max = times[i]; 48 | maxIndex = i; 49 | } 50 | } 51 | 52 | int h = maxIndex/60; 53 | int m = maxIndex%60; 54 | if(h < 10) 55 | cout << "0"; 56 | cout << h << ":"; 57 | if(m < 10) 58 | cout << "0"; 59 | cout << m; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کاغذ کادو چهارضلعی/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | long double a, b, c, d; 12 | cin >> a >> b >> c >> d; 13 | 14 | long double s = (a + b + c + d)/2; 15 | cout << setprecision(12) << sqrt((s-a)*(s-b)*(s-c)*(s-d)); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کاف کیک/Test.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.*; 4 | 5 | public class Test{ 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt() , k = sc.nextInt(); 11 | int [] c = new int [n]; 12 | int firstElement = 0, lastElement = 0; 13 | int max = 0 , min = 100 , max2 = 0, min2 = 100; 14 | for (int i = 0; i < n; i++) { 15 | c[i] = sc.nextInt(); 16 | firstElement = c[0]; 17 | lastElement = c[n-1]; 18 | if (c[i] > max) 19 | max = c[i]; 20 | else if (c[i] < min) 21 | min = c[i]; 22 | 23 | } 24 | 25 | if (k == 1) 26 | System.out.println(max); 27 | else { 28 | if (k == 2) 29 | System.out.println(Math.min(firstElement, lastElement)); 30 | else if (k >= 3) 31 | System.out.println(min); 32 | } 33 | 34 | 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کامل بودن یا نبودن/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "iostream.h" 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int a, b, c, n; 8 | cin>> n; 9 | 10 | c = 0; 11 | 12 | for(int i =1; i!=n; i++) 13 | { 14 | if(n % i == 0) 15 | { 16 | c += i; 17 | } 18 | } 19 | 20 | if(c == n) 21 | { 22 | cout <<"YES"; 23 | } 24 | 25 | else 26 | { 27 | cout<<"NO"; 28 | } 29 | 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کامل بودن یا نبودن/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int number = sc.nextInt(); 11 | int count = 0; 12 | 13 | for (int i = 1; i <= number / 2;i++) { 14 | if(count == number) { 15 | count += i; 16 | } 17 | } 18 | 19 | if(count == number) { 20 | System.out.println("YES"); 21 | } 22 | else { 23 | System.out.println("No"); 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کامل بودن یا نبودن/completeOrNot.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | sum = 0 4 | for i in range(1, n): 5 | if n % i == 0: 6 | sum += i 7 | if sum == n: 8 | print("YES") 9 | else: 10 | print("NO") 11 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کدتخفیف/Test3.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Test3 { 5 | // کد تخفیف 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | String t = sc.next(); 10 | String[] s = new String[n]; 11 | boolean Found = false; 12 | boolean found2 = false; 13 | 14 | for (int i = 0; i < n; i++) { 15 | s[i] = sc.next(); 16 | } 17 | 18 | 19 | 20 | for (int k = 0; k < n; k++) { 21 | int countT = 0, countS = 0; 22 | boolean failure = false; 23 | for (int i = 0; i < t.length(); i++) { 24 | for (int j = 0; j < s[k].length(); j++) { 25 | if (t.charAt(i) == s[k].charAt(j) ){ 26 | countT++; 27 | break; 28 | } 29 | } 30 | } 31 | if (countT == t.length()) 32 | Found = true; 33 | else 34 | Found = false; 35 | 36 | for (int j = 0; j < s[k].length(); j++) { 37 | for (int i = 0; i < t.length(); i++) { 38 | if (s[k].charAt(j) == t.charAt(i) ){ 39 | countS++; 40 | break; 41 | } 42 | } 43 | } 44 | 45 | if (countS == s[k].length()) 46 | found2 = true; 47 | else 48 | found2 = false; 49 | 50 | if (!Found | !found2) 51 | failure = true; 52 | 53 | if (failure) 54 | System.out.println("No"); 55 | else 56 | System.out.println("Yes"); 57 | } 58 | 59 | 60 | 61 | sc.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کشمش در پارک/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, m; 7 | cin >> n >> m; 8 | long long jad[n][m], dp[n][m]; 9 | for(int i=0; i> jad[i][j]; 12 | 13 | long long maximum_of_all = 0; 14 | memset(dp, 0, sizeof(long long)*n*m); 15 | 16 | for(int i=n-1; i>=0; i-=2) 17 | { 18 | for(int j=m-1; j>=0; j--) 19 | { 20 | if(jad[i][j] == 0) 21 | continue; 22 | if(i == n-1) 23 | dp[i][j] = jad[i][j]; 24 | int paiin; 25 | if(((n-1)/2 - i/2)% 2 == 0) 26 | paiin = j-1; 27 | else 28 | paiin = j+1; 29 | 30 | if(i < n-1 && paiin >= 0 && paiin <= m-1 && dp[i+2][paiin] != 0) 31 | dp[i][j] = max(dp[i][j], jad[i][j] + dp[i+2][paiin]); 32 | if(j < m-1 && dp[i][j+1] != 0) 33 | dp[i][j] = max(dp[i][j], jad[i][j] + dp[i][j+1]); 34 | } 35 | } 36 | 37 | for(int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | #define ll unsigned long long 6 | 7 | int main() 8 | { 9 | string ns; 10 | cin >> ns; 11 | 12 | if(ns.length() == 1) 13 | { 14 | if((int)(ns[0]-'0') <= 2) 15 | cout << ns; 16 | else 17 | cout << (int)(ns[0] - '0') - 1; 18 | } 19 | else 20 | { 21 | for(int i=ns.length()-1; i>=0; i--) 22 | { 23 | if(ns[i] >= '1') 24 | { 25 | ns[i] -= 1; 26 | break; 27 | } 28 | else 29 | { 30 | ns[i] = '9'; 31 | } 32 | } 33 | if(ns[0] == '0') 34 | { 35 | ns.erase(0,1); 36 | } 37 | 38 | cout << ns; 39 | } 40 | 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کلید چراغ/KilidCheraq.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | 3 | count = 0 4 | lamp = [] 5 | for i in range(n): 6 | lamp.append(int(input())) 7 | 8 | for i in range(n): 9 | if i == (n-1): 10 | break 11 | elif lamp[i] != lamp[i+1]: 12 | count+=1 13 | 14 | print(count) 15 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کلید چراغ/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int n = sc.nextInt(); 9 | int changeStateCount = 0; 10 | int lastState = 0; 11 | int tempState = 0; 12 | 13 | for (int i = 1; i<=n; i++) { 14 | tempState = sc.nextInt(); 15 | 16 | if(i == 1) { 17 | lastState = tempState; 18 | } 19 | else if(i > 1 && lastState != tempState) { 20 | lastState = tempState; 21 | changeStateCount++; 22 | } 23 | } 24 | 25 | System.out.println(changeStateCount); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کمک به کاپی/AMK-solution/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | String inp = sc.nextLine(); 11 | String[] inp_arr = inp.split(" "); 12 | 13 | 14 | for (int i = 1; i <= Integer.parseInt(inp_arr[0]);i++) 15 | System.out.print("copy of "); 16 | 17 | System.out.print(inp_arr[1]); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کمک به کاپی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | * 6 | * simpler solution without need of using array. 7 | */ 8 | public class Test { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | String s = sc.next(); 14 | for (int i = 0; i < n; i++) { 15 | System.out.print("copy of "); 16 | } 17 | System.out.println(s); 18 | 19 | sc.close(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کوچک بزرگ/answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | bool isPrime(int num) 6 | { 7 | if(num == 1) 8 | return false; 9 | for(int i=2; i<=sqrt(num); i++) 10 | { 11 | if(num % i == 0) 12 | return false; 13 | } 14 | return true; 15 | } 16 | 17 | int main() 18 | { 19 | int n; 20 | cin >> n; 21 | if(n == 1) 22 | { 23 | cout << 1; 24 | return 0; 25 | } 26 | else if(n == 4) 27 | { 28 | cout << 4; 29 | return 0; 30 | } 31 | 32 | for(int i=n; i>=1; i--) 33 | { 34 | if(isPrime(i)) 35 | { 36 | cout << i; 37 | break; 38 | } 39 | } 40 | return 0; 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/کوین و قدرت شالاپ/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * Created by AMK on 7/28/2019. 5 | * Life is nice :) 6 | * Enjoy coding :D 7 | */ 8 | public class Main { 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | double n = scanner.nextInt(); 12 | long sum = 0; 13 | for (int i = 0; i < n / 2; i++) { 14 | sum += i; 15 | } 16 | sum = sum * 2; 17 | if (n % 2 == 0){ 18 | sum += n / 2; 19 | } 20 | n++; 21 | System.out.println(sum/n); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/گردو شکستم/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * @Author: Mohammadyar Barandov 5 | */ 6 | public class Test { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt(); 11 | 12 | long max = Math.max(x,y); 13 | long min = Math.min(x,y); 14 | 15 | long reminder = n % max, result = n / max; 16 | long minReminder = n % min , minResult = n / min; 17 | 18 | 19 | if (reminder == min) 20 | if (x == max) 21 | System.out.println(result+" "+"1"); 22 | else 23 | System.out.println("1"+" "+result); 24 | else if (minReminder == 0) 25 | if (x == min) 26 | System.out.println(minResult+" "+minReminder); 27 | else 28 | System.out.println(minReminder+" "+minResult); 29 | else { 30 | if (x + y == n/2) 31 | System.out.println("2 2"); 32 | else if (x>n & y>n) 33 | System.out.println(-1); 34 | else if (x>n & y==n) 35 | System.out.println("0 1"); 36 | else if (x==n & y>n) 37 | System.out.println("1 0"); 38 | 39 | else { 40 | 41 | if ((result * max) + (reminder * min) == n) 42 | if (x == max) 43 | System.out.println(result + " " + reminder); 44 | else 45 | System.out.println(reminder + " " + result); 46 | else if (((n-max) % min) == 0) 47 | if (x == min) 48 | System.out.println(((n-max) / min)+" "+"1"); 49 | else 50 | System.out.println("1"+" "+((n-max) / min)); 51 | else 52 | System.out.println("-1"); 53 | } 54 | } 55 | 56 | 57 | sc.close(); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/گزارش کار/GozaresheKar.py: -------------------------------------------------------------------------------- 1 | n , k = input().split() 2 | n = int(n) 3 | k = int(k) 4 | sum = 0 5 | for i in range (n): 6 | c = int(input()) 7 | sum += c 8 | if k <= sum: 9 | print("YES") 10 | else: 11 | print("NO") 12 | 13 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یافتن عدد اول/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int temp_n = n; 12 | int b=0; 13 | int count; 14 | int counter = 1; 15 | 16 | while (n > 0) { 17 | b += n % 10; 18 | n = n / 10; 19 | } 20 | 21 | int i=temp_n; 22 | int j; 23 | while(true) { 24 | i++; 25 | count = 0; 26 | for (j=1;j <= i;j++) 27 | if(i%j==0) 28 | count++; 29 | 30 | if(count==2 && counter==b) { 31 | System.out.println(i); 32 | break; 33 | } 34 | else if(count==2) 35 | counter++; 36 | } 37 | 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یخدارچی/AMK-solution/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static Scanner sc; 6 | 7 | 8 | public static void main(String[] args) { 9 | sc = new Scanner(System.in); 10 | int T = sc.nextInt(); 11 | 12 | if(T < -273 || T >= 6000) 13 | return; 14 | 15 | if(T > 100) 16 | System.out.println("Steam"); 17 | else if(T < 0) 18 | System.out.println("Ice"); 19 | else 20 | System.out.println("Water"); 21 | 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یخدارچی/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // Better Solution 9 | 10 | int T = sc.nextInt(); 11 | 12 | 13 | if(T > 100){ 14 | System.out.println("Steam"); 15 | } else if (T < 0){ 16 | System.out.println("Ice"); 17 | }else 18 | System.out.println("Water"); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یخدارچی/practice.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | if t > 100: 3 | print('Steam') 4 | elif t < 0: 5 | print("Ice") 6 | else: 7 | print('Water') -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یک ساعت/Test.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | 5 | /** 6 | * @Author: Mohammadyar Barandov 7 | * 8 | */ 9 | 10 | public class Test { 11 | 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | int a = sc.nextInt() , b = sc.nextInt(); 15 | 16 | if (a != 0 & b!=0) { 17 | a = Math.abs(12 - a); 18 | b = Math.abs(60 - b); 19 | if (a<10 & b <10) 20 | System.out.println("0"+a+":"+"0"+b); 21 | else if (a <10 & b>=10) 22 | System.out.println("0"+a+":"+b); 23 | else if (a>=10 & b<10) 24 | System.out.println(a+":0"+b); 25 | else 26 | System.out.println(a+":"+b); 27 | } 28 | else if (a==0 & b==0) 29 | System.out.println("00:00"); 30 | else if (a==0){ 31 | b = Math.abs(60 - b); 32 | if (b<10) 33 | System.out.println("00:0"+b); 34 | else 35 | System.out.println("00:"+b); 36 | } 37 | else if (b==0) { 38 | a = Math.abs(12 - a); 39 | if (a < 10) 40 | System.out.println("0" + a + ":00"); 41 | else 42 | System.out.println(a + ":00"); 43 | } 44 | sc.close(); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یک سوال ساده/Main.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | 12 | for (int i = 0; i < n; i++) { 13 | System.out.println("man khoshghlab hastam"); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /پاسخ سوالات کوئرا/یک سوال ساده/practice.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | for i in range (n): 3 | print("man khoshghlab hastam") --------------------------------------------------------------------------------