|
|
Common Boardusing System; class Program { static void Main() { int[] n = new int[3]; string[][] val = new string[3][]; int count = 0; for(int i = 0; i < 3; i++) { n[i] = int.Parse(Console.ReadLine()); val[i] = Console.ReadLine().Split(' '); } for(int i = 0; i < n[0]; i++) { for(int k = 0; k < n[1]; k++) { if(val[0][i] == val[1][k]) { for(int j = 0; j < n[2]; j++) { if(val[0][i] == val[2][j]) { count++; break; } } } } } Console.WriteLine(count); } } using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string[] move = new string[n]; for(int i = 0; i < n; i++) { move[i] = Console.ReadLine(); } for(int i = 0; i < n; i++) { if(move[i][0] >= 'c' && move[i][0] <= 'f' && move[i][1] >= '3' && move[i][1] <= '6') { Console.WriteLine(8); } else if(((move[i][0] == 'b' || move[i][0] == 'g') && move[i][1] >= '3' && move[i][1] <= '6') || ((move[i][1] == '2' || move[i][1] == '7') && move[i][0] >= 'c' && move[i][0] <= 'f')) { Console.WriteLine(6); } else if(move[i] == "a1" || move[i] == "a8" || move[i] == "h8" || move[i] == "h1") { Console.WriteLine(2); } else if((move[i][0] == 'a' && (move[i][1] == '2' || move[i][1] == '7')) || (move[i][0] == 'b' && (move[i][1] == '1' || move[i][1] == '8')) || (move[i][0] == 'g' && (move[i][1] == '1' || move[i][1] == '8')) || (move[i][0] == 'h' && (move[i][1] == '2' || move[i][1] == '7'))) { Console.WriteLine(3); } else Console.WriteLine(4); } } } Autors! you are wrong. fix please. It's allright! You cannot have two neighbour stair steps with horizontal difference more than 1. Hello guys, I've just started learning algorithms and I've read a piece from R. Sedgewick's book on Algorithms about Union Find. I'd love to practice it. Could anyone recommend any problems here? Thanks. Can anybody give me test 8? Code on python2: a, b = map(int, raw_input().split(' ')) k = 0 c = map(int, raw_input().split(' ')) for x in xrange(1,10): k = k+c[x]*20 if b-k>a: print('No chance.') elif b-k<a: print('Dirty debug :(') elif b-k==a: print('No chance.') xrange(1, 10) only takes array elements 1-9. You need to use xrange(0, 10) to get elements 0-9 next_permutation() generates distinct permutations of a given iterable object (vector, string, etc). Just make 6 permutations, and save each of them in a set<vector<int> >. Finally, check if the size of the set is 6, because the set only saves different elements. Pretty easy solution. Here is my code. What is wrong? Help, please! var m,n:int64; k,i:0..20; a:array[1..20] of int64; begin read(n,k); for i:=1 to k do read(a[i]); for i:=2 to k do if a[i]<a[i-1] then begin m:=a[i]; a[i]:=a[i-1]; a[i-1]:=m end; m:=n-(n-a[1])-(n-a[2]); if m<=0 then write(0) else write(m); end. Edited by author 02.11.2013 04:21 You must only write((a1+a2+...+ak)-n) That's all)) Good luck! no, right answer is ((a1+a2+...+ak)-n * (k-1)) #include <iostream> using namespace std; int main() { int a[3],b[3]; for (int i = 0;i<3;i++) {cin>>a[i]>>b[i]; } cout<<a[0]-a[2]<<b[0]-b[1]; return 0; } You forgot the space. Where am I must write the space? Only in output? between ans1 << " " << ans2; i can not submit my solution by java What is wrong? import java.util.*; public class Main { public static void main(String[] args){ int a,b = 0;
Scanner in = new Scanner(System.in);
System.out.println("First num"); a = in.nextInt(); if(a==1){ System.out.println("Second num"); b = in.nextInt();} if(b==5){ System.out.println(a+b); } } } You should not write any other message than the expected output. How should the compiler know that writing "First num" and "Second num" isn't part of the problem result? Edited by author 29.08.2014 23:25 big int will be wrong What is the problem import java.util.Scanner; public class Summa { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan=new Scanner( System.in); System.out.println("Введите значение a"); int a; a=scan.nextInt(); System.out.println("Введите значение b"); int b; b=scan.nextInt(); System.out.println(" a + b = " + (a + b)); } } You should not write any other message than the expected output. what is the problem? package Acm; import java.util.Scanner; public class Num { public static void main(String[] args) { // TODO Auto-generated method stub Scanner numscanner = new Scanner(System.in); int a = numscanner.nextInt(); int b = numscanner.nextInt(); System.out.println(a + b); } } Isn't Test#5 the n=500 one? n = 2 the answer is 2 , isn't it? Try this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 White c6-d7 Incorrect 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 I had WA9 because i thought there would be only one king of the same color, but seems like actually there might be more. Thankfully to take more kings into account i had to delete some of my code rather than add some. An example test: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 6 0 6 0 0 0 0 0 1 White <any move> (for example a1-a2 or c1-c2) The answer is "Incorrect" and then a table, because no matter what white does, there's at least one king remaining under check. Also had WA7 because of using shortint and a bit too small constant for amount of available moves. After changing from 100 to 300 and from shortint to longint got AC. An example test, where white have 288 available moves: 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 1 White a1-b2 Result: "Draw" and table output. Edited by author 11.01.2016 03:55 use cin.eof() to judge the end of input and get WA 3; scanf get AC and while(cin >> a) may case Time Out why does cin.eof() produces WA 3 ? You should use while(scanf("%lf", &a)) #include<iostream> #include<math.h> int main() { using namespace std; int i; float r,a[128*64]; unsigned long long n,j,k; for(i=0;i<n;i++) cin>>a[i]; j=n-1; for(k=j;k>=0;k--) { r=sqrt(a[k]); cout<<r<<"\n"; } return 0; } You should try to increase the size of your array and perhaps use a double array over float. > A size of the input stream does not exceed 256 KB Minimum number of chars per number is 2 - "0 ". So you have to receive up to 128 K numbers. Your array is about 8 K numbers. You shouldn't allocate such big arrays on stack. Use dynamic allocation or std::vector. And another note. > unsigned long long n,j,k; > for(i=0;i<n;i++) > cin>>a[i]; How many times will this for iterate? Why? Edited by author 15.12.2015 21:02 It's preferable to use a double precision floating point type over a single float. n is not given in the input data. I recommend to use std::vector to alloc it: vector <double> input; double aux; while(cin>>aux) input.push_back(aux); Edited by author 10.01.2016 23:58 |
|
|