1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 | /****************************************************************
* Description: 2016_J_27
* Author: Alex Li
* Date: 2023-09-06 17:30:51
* LastEditTime: 2023-09-06 17:43:04
****************************************************************/
#include <iostream>
using namespace std;
int readint(){
int num=0;
int negative=0;
char c;
c=cin.get();//cin.get自代的函数,一个字符一个字符读取
while((c<'0'||c>'9')&&c!='-')//如果c不在0~9之间,并且上一行读进来不是'-'
c=cin.get; //while上面条件不满足,说明读到有效字符(0~9或'-')
if(c=='-')//如果是-,标志negative是1,表示此数是负
negative=1;
else
num=c-'0'; //将字符转成数学
c=cin.get(); //读入下一个字符
while (c>'0'&&c<='9'){ //如果是0~9之间的字符
num=num*10+c-'0'; //之前的数字*10,新读的字符转数字
c=cin.get(); //不停的读
}
if(negative==1) //如果negative是1,说明是负数
num=-num;
return num;
}
int main(){
int a,b;
a=readint(); b=readint();//调用两次函数
cout<<a<<endl<<b<<endl;
return 0;
}
|