各种语言版本的程序样例集
2016-05-05 14:04
429 查看
各种语言版本的程序样例集
以下样例程序可用于解决这道简单的题目:读入2个整数A和B,然后输出它们的和。awk (.awk)
{print $1 + $2}
bash (.sh)
while read i; do echo $((${i/ /+})) done
clang (.c)
#include <stdio.h> int main() { int a, b; while(scanf("%d %d",&a, &b) != EOF) printf("%d\n", a + b); return 0; }
clang++ (.cpp)
#include <iostream> using namespace std; int main() { int a, b; while (cin >> a >> b) cout << a+b << endl; return 0; }
clisp (.cl)
(loop for n = (read t nil nil) while n do (format t "~d~C" (+ n (read)) #\linefeed))
fpc (.pas)
var a, b: integer; begin while not eof(input) do begin readln(a, b); writeln(a + b); end; end.
gcc (.c)
#include <stdio.h> int main() { int a, b; while(scanf("%d %d",&a, &b) != EOF) printf("%d\n", a + b); return 0; }
g++ (.cpp)
#include <iostream> using namespace std; int main() { int a, b; while (cin >> a >> b) cout << a+b << endl; return 0; }
gccgo、go (.go)
package main import "fmt" func main() { var a, b int for { n, _ := fmt.Scanf("%d %d", &a, &b) if (n != 2) { break } fmt.Println(a + b) } }
gcj (.gcj.java)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); try { while (in.hasNextInt()) { int a = in.nextInt(); int b = in.nextInt(); System.out.println(a + b); } } catch (NullPointerException ex) { // gcj Scanner has a bug that throws NPE ; } } }
ghc (.hs)
main = interact $ unlines . map (show . sum . map read . words) . lines
javac (.java)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int a = in.nextInt(); int b = in.nextInt(); System.out.println(a + b); } } }
lua (.lua)
for a, b in io.read('*a'):gmatch('([%d-]+) ([%d-]+)') do print(tonumber(a) + tonumber(b)) end
mcs (.cs)
public class Program { public static void Main() { string line; while ((line = System.Console.ReadLine ()) != null) { string[] tokens = line.Split(); System.Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } }
node (.js)
var fs = require('fs'); var buf = ''; process.stdin.on('readable', function() { var chunk = process.stdin.read(); if (chunk) buf += chunk.toString(); }); process.stdin.on('end', function() { buf.split('\n').forEach(function(line) { var tokens = line.split(' ').map(function(x) { return parseInt(x); }); if (tokens.length != 2) return; console.log(tokens.reduce(function(a, b) { return a + b; })); }); });
ocamlc (.ml)
try while true do Scanf.scanf " %d %d" (fun a b -> Printf.printf "%d\n" (a + b)) done; None with End_of_file -> None ;;
perl (.pl)
#!/usr/bin/perl -pla $_ = $F[0] + $F[1]
php (.php)
<?php while (fscanf(STDIN, "%d%d", $a, $b) == 2) { print ($a + $b) . "\n"; }
python2, 3 (.py) (注意python3应使用 input() 读输入)
import sys for line in sys.stdin: print(sum(map(int, line.split())))
racket (.rkt)
#lang racket (define (f) (let ([n (read)]) (if (eof-object? n) (void) (begin (displayln (+ (read) n)) (f))))) (f)
ruby (.rb)
STDIN.each_line do |line| puts line.split.map(&:to_i).inject(:+) end
valac (.vala)
public static int main(string[] args) { int a = 0, b = 0; while (stdin.scanf("%d%d", &a, &b) == 2) { stdout.printf("%d\n", a + b); } return 0; }
vbnc (.vb)
Module Program Sub Main() Do Dim line As String = Console.ReadLine() If line Is Nothing Then Exit Do Dim a() As String = line.Split(" "c) Console.WriteLine(CInt(a(0)) + CInt(a(1))) Loop End Sub End Module
相关文章推荐
- 原生js和jquery分别实现伸缩菜单的制作-水平方向导航栏
- eclipse+sdk配置问题
- Pig
- Golang strings 包 用法详解
- 安卓国际化之翻译编辑器
- sed 批量处理字符串
- 各种语言版本的程序样例集
- 根据出生日期计算年龄的sql各种数据库写法
- POJ 1017-Packets(贪心)
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
- C++第5次作业
- CI框架去除index.php
- HTTP 错误 404.2 - Not Found 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页
- asp发送邮件
- zabbix监控windows 服务器各项性能
- 【fastweixin框架教程6】微信企业号给关注的用户主动发送推送消息
- odoo调试端口8072问题
- PopWindow 自定义
- 特征选择方法:卡方检验和信息增益
- GradleUserGuide中文版 21)Java插件 22)War插件