AFO
聊天

不要随便机惨别人
打一些简简单单的a+b Problem
C:
C#include<stdio>
int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
C++:
C++#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<a+b<<'\n';
}
python
代码a = input()
b = input()
print(a+b)
html和css不能实现a+b,所以我把它们和js结合起来了
HTML+JS+CSS:
HTML<!DOCTYPE html>
<html>
<head>
<title>a+b Problem</title>
<meta charset="utf-8">
<!--这里是css代码-->
<style type="text/css">
*{
text-align: center;
}
input{
border-style: dashed;
}
input:hover{
border-style: dashed;
background-color: grey;
}
button{
height: 30px;
width: 60px;
background-color: white;
color: black;
}
button:hover{
height: 30px;
width: 60px;
background-color: black;
color: white;
}
</style>
</head>
<body>
请输入a:<input type="text" id="a">
<br>
请输入b:<input type="text" id="b">
<br>
<button onclick="return mainfunc();">答案</button>
<p id="out"></p>
<!--JavaScript-->
<script type="text/javascript">
function mainfunc(){
var a = new Number(document.getElementById("a").value);
var b = new Number(document.getElementById("b").value);
//typeof a;
if(isNaN(a) || isNaN(b))
document.getElementById("out").innerHTML = "输入两个数!";
else
document.getElementById("out").innerHTML = "答案是:"+String(a+b);
}
</script>
</body>
</html>
PHP:
php//默认读写文件分别是a.in和a.out,因为php没有控制台输入输出
<?php
$in = fopen("a.in", "r");
$out = fopen("a.out","w");
$a = intval(fgets($in));
$b = intval(fgets($in));
$ans = strval($a+$b).PHP_EOL;
fwrite($out, $ans);
?>
//这个是交在洛谷上能ac的
//输入文件是"php://stdin"
//输出直接使用"echo"
<?php
$file = fopen("php://stdin","r");
list($a,$b) = explode(" ",fgets($file));
echo $a+$b;
?>
大逝祭
- 2022.7.12 注册
- 2022.8.12 第一次举报
同学别人
- 2022.8.23 军训结束