14 条题解
-
5
BZOJ 官方题解:
Q: Where are the input and the output? A: Your program shall always read input from stdin (Standard Input) and write output to stdout (Standard Output). For example, you can use
scanf
in C orcin
in C++ to read from stdin, and useprintf
in C orcout
in C++ to write to stdout. You shall not output any extra data to standard output other than that required by the problem, otherwise you will get aWrong Answer
. User programs are not allowed to open and read from/write to files. You will get aRuntime Error
or aWrong Answer
if you try to do so. Here is a sample solution for problem 1000 using C++/G++:#include <iostream> using namespace std; int main() { int a,b; cin >> a >> b; cout << a+b << endl; return 0; }
It's important that the return type of main() must be int when you use G++/GCC,or you may get compile error. Here is a sample solution for problem 1000 using C/GCC:
#include <stdio.h> int main() { int a,b; scanf("%d %d",&a, &b); printf("%d\n",a+b); return 0; }
Here is a sample solution for problem 1000 using PASCAL:
program p1000(Input,Output); var a,b:Integer; begin Readln(a,b); Writeln(a+b); end.
Here is a sample solution for problem 1000 using JAVA: Now java compiler is jdk 1.5, next is program for 1000
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); int a=cin.nextInt(),b=cin.nextInt(); System.out.println(a+b); } }
Old program for jdk 1.4
import java.io.*; import java.util.*; public class Main { public static void main (String args[]) throws Exception { BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); String line = stdin.readLine(); StringTokenizer st = new StringTokenizer(line); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); System.out.println(a+b); } }
-
0
水题一道。 这里大家可以看到世界各大语言的代码:
C
#include <stdio.h> int main() { int a,b; scanf("%d%d",&a,&b); printf("%d\n", a+b); return 0; }
C++
#include <iostream> #include <cstdio> using namespace std; int main() { int a,b; cin >> a >> b; cout << a+b << endl; return 0; }
Pascal
var a, b: longint; begin readln(a,b); writeln(a+b); end.
Python
s = input().split() print(int(s[0]) + int(s[1]))
Java
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); int a = cin.nextInt(), b = cin.nextInt(); System.out.println(a+b); } }
PHP
<?php $input = trim(file_get_contents("php://stdin")); list($a, $b) = explode(' ', $input); echo $a + $b;
Ruby
a, b = gets.split.map(&:to_i) print a+b
Rust
use std::io; fn main(){ let mut input=String::new(); io::stdin().read_line(&mut input).unwrap(); let mut s=input.trim().split(' '); let a:i32=s.next().unwrap() .parse().unwrap(); let b:i32=s.next().unwrap() .parse().unwrap(); println!("{}",a+b); }
Go
package main import "fmt" func main() { var a, b int fmt.Scanf("%d%d", &a, &b) fmt.Println(a+b) }
-
-5
C++11の高端的题解!
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<string> #include<cstdlib> using namespace std;//超长无关紧要的高端的头文件 int a,b;//定义高端的变量 int main(){ scanf("%d%d",&a,&b);//快速读入高端的变量 printf("%d",a+b);//经过简简单单的高端的计算后,快速输出高端的结果! return 0;//高端而潇洒的结尾~ }
看这高端的注释,不点个赞吗?
-
-9
来一发
dijkstra
题解#include<bits/stdc++.h> using namespace std; int n,m,s; int head[100010],cnt=-1; bool done[100010]={0}; long long ans[100010]; struct edge { int to,next,w; }e[200010]; void add(int u,int v,int w) { e[++cnt].next=head[u]; head[u]=cnt; e[cnt].to=v,e[cnt].w=w; } struct node { long long num,value; bool operator <(const node &x) const{return value>x.value;} node(long long num_,long long value_):num(num_),value(value_){} }; priority_queue<node>dis; void dijkstra() { while(!dis.empty()) { node u=dis.top(); dis.pop(); if(done[u.num]==1)continue; done[u.num]=1; ans[u.num]=u.value; for(int i=head[u.num];~i;i=e[i].next) { int v=e[i].to; if(done[v])continue; dis.push(node(v,u.value+e[i].w)); } } } int main() { int a,b; cin>>a>>b; n=3,m=2,s=1; for(int i=1;i<=n;i++) head[i]=-1,dis.push(node(i,2147483647)); add(1,2,a),add(2,3,b); dis.push(node(s,0)); dijkstra(); cout<<ans[3]<<endl; return 0; }
- 1
信息
- ID
- 1000
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- (无)
- 递交数
- 650
- 已通过
- 430
- 上传者