hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha a = input() b = input() print a + b it is wrong answer, why? the example code in "how to write python solutions" is functional programming style. I supposed thats what is acceptable. By the way, neither works with raw_input() and int() you should try to use raw_input().split() because the input is in the same line listname[0]+listname[1] I won't include the correct solution Edited by author 05.08.2015 18:11 Edited by author 05.08.2015 18:12 #include <iostream> using namespace std; int main() { int a, b; cout << "Enter 'a': "; cin >> a; cout << '\n'; cout << "Enter 'b': "; cin >> b; cout <<'\n'; cout << a + b; return 0; } Edited by author 07.06.2015 21:38 Edited by author 07.06.2015 21:38 Don't output "Enter a" or something like that Don't output "Enter a" or something like that Значения a и b вводятся через пробел, поэтому надо использовать только cin >> a >> b; I want to submit the solution in C language. What language I should choose from the option and what is the error in following coding:- #include <stdio.h> int main() { double a,b; scanf("%lf %lf",&a,&b); printf("%lf",a+b); return 0; } Edited by author 31.03.2015 20:19 Use integral type (int, long, long long) or set precision in output format string printf("%0.0lf",a+b); #include <iostream> int main() { int a=1+5; std::cout<<a; } Input numbers are not always 1 and 5, they are given to your stdin. import java.io.BufferedReader; import java.io.InputStreamReader; public class AB { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(reader.readLine()); int b = Integer.parseInt(reader.readLine()); System.out.println(a+b); } } У меня такое же решение. Тоже не принимает... Numbers are located at the same line. So, first call of readLine() give you "a b", and second - null. #include <iostream> using namespace std; int main() { int a, b; cout << "Enter the first number: "; cin >> a; cout << "Enter the second number: "; cin >> b; cout <<"the result: "<< a + b << endl; return 0; } Комментарии к вводу уберите import java.io.*; import java.util.*; public class TokenExplain { public static void main(String[] args) throws IOException { //this program gets two tokens on a single line and calculates their sum StreamTokenizer in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); in.nextToken(); int a=(int)in.nval; in.nextToken(); int b=(int) in.nval; System.out.println(a+b); }
} As you can see, it was well written, but when it was compiled, it took 0.078 seconds while i see fellow java coders clocking speed of 0.031, can you suggesting better classes to read inputs instead of the one i used, all other suggestions are highly welcome It has no problem and can be accepted. Yes, it was accepted but that is not the issue. The real issue is how i can optimize the code in such a way to clock 0.031 sec that others clocked. Thanks. But I cant find the code which clock 0.031 by google. Can anyone help me? #include <iostream> using namespace std; int main() { int a=1, b=5, sum=0; sum=a+b; cout<<sum<<endl; return 0; } Ты вводишь два числа, а не определяешь в коде. А система проверки может дать тебе любые два числа, не обязательно a=1 и b=5 ты должен ввести входные данные выводные данные a = input() b = input() a = int(a) b = int(b) c = a+b print c
this should be correct isn't it ? It is correct in Python 2, though explicit cast is excessive. In Python 3, use should add brackets after 'print'. 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 program outputs: Введите значение a Введите значение b a + b = 6 istead of just 6 Edited by author 03.10.2014 11:2031 байт ни кто короче уже не сделает //********************************************* //FreePascal 2.0.4 var a,b,u:longint; begin readln(a,b); for u:=1 to b do inc(a); writeln(a); end. //********************************************* //Visual C# 2010 using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } //********************************************* //Java 1.7 import java.util.Scanner; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(sc.nextInt() + sc.nextInt()); } } #include<iostream> using namespace std ; int main() { int a, b ; cout<<"Plz enter two numbers: "<<'\n' ; cin>> a >> b ; cout<<"Here is your output: "<< a + b <<'\n' ; return 0 ; } what's the wrong!!! I've written this code in c++ and submitted under visual c++2010 but they don't accept it..why????? Because you write some text in output. Remove all text. #include<iostream> using namespace std ; int main() { int a, b ; cin>> a >> b ; cout<< a + b ; return 0 ; } Like this thanks for your answer :) using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } import java.util.Scanner; public class firstexercise{ public static void main(String[]args){ Scanner scanner=new Scanner(System.in); int c=0; System.out.println("Введите первое число."); int a=scanner.nextInt(); System.out.println("Введите второе число."); int b=scanner.nextInt(); c=a+b; System.out.println("Ответ = " + c); } } There should be no prompt message and output only answer: import java.util.Scanner; public class firstexercise{ public static void main(String[]args){ Scanner scanner=new Scanner(System.in); int c=0; int a=scanner.nextInt(); int b=scanner.nextInt(); c=a+b; System.out.println(c); } } #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; return 0; } after int main() need "{" #include <fstream> using namespace std; int main() { ifstream fin("INPUT.TXT"); ofstream fout("OUTPUT.TXT"); int a,b; fin >> a >> b; fout << a + b; fin.close(); fout.close(); } поидет ?? Мен агылшынша тiлде белмимын!! How to respond to the tasks in your site? a file or command line? tell me if the command line .. Read FAQ Кай жерде ' read' ? Корсетше мағам .. namespace Project1 { class Programa { static void Main() { Console.Write("Введите первое число: "); int First = Convert.ToInt32(Console.ReadLine()); Console.Write("Введите второе число: "); int Second = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Сумма числа {0} и числа {1} равна {2}", First, Second, (First + Second)); Console.ReadKey(); } } } Edited by author 18.01.2013 23:09 Edited by author 18.01.2013 23:09 or namespace Project2 { class adsf { static void Main() {
int x; int y;
x = Convert.ToInt32(Console.ReadLine()); y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Сумма числел = " + (x+y));
Console.ReadKey(); } } } #include <iostream> int main() { using namespace std; int a, b, buffer; cin>>a>>b; int *mass=new int[b]; int *deep=new int[33180]; for (int i4=0; i4<b; i4++) { mass[i4]=0; deep[i4]=1200; } for (int i5=b; i5<33180; i5++) { deep[i5]=a; } for (int i6=0; i6<33180; i6++) { for (int i9=1; i9<33180; i9++) { if (deep[i9-1]>deep[i9]) { buffer=deep[i9-1]; deep[i9-1]=deep[i9]; deep[i9]=buffer; } } } mass[0]=a; mass[b-1]=b; for (int i=0; i<b; i++) { for (int i2=1; i2<b; i2++) { if (mass[i2-1]>mass[i2]) { buffer=mass[i2-1]; mass[i2-1]=mass[i2]; mass[i2]=buffer; } } } int sum=0; for (int i3=0; i3<b; i3++) { sum+=mass[i3]; } cout<<sum; delete []deep; delete []mass; return 0; } This solution works 1 second and output 1 if a=1 or b=1, and get AC! ab = raw_input() print int(ab[0]) + int(ab[2]) package timus; class timus {
public static void main (String args[]) { int a = 1,b = 5; System.out.println(a+b); } } Edited by author 20.01.2014 23:38 Edited by author 20.01.2014 23:38 |
|