c++ 刷题之输入输出

刷多了LeetCode,就容易把基本的输入输出给忘了,但是有些OJ得自己输入输出,总结一波,以备不时之需 。

++
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
void split(string s,string separator,vector<string>& vec);
int main(int argc, char **argv) {
//c++ 多行整型
// int a,b,c;
// while(cin>>a>>b>>c){//ctrl+d
// cout<<a<<b<<c<<endl;
// }
// cout<<"DONE!"<<endl;
//c 多行整型
// int a,b,c;
// while(scanf("%d%d%d",&a,&b,&c)!=EOF){//linux ctrl+d结束输入;windows ctrl+z结束
// if(!(a||b||c)) break;
// printf("%d,%d,%d\n",a,b,c);
// }
// printf("%s","DONE!");
//c++ 多行短字符串,无空格隔开 & 字符串修改
// string a;
// while(cin>>a){
// cout<<"cout:"<<a<<"len:"<<a.length()<<endl;
// }
// string finish="DONE!";
// finish[2]='O';
// finish[3]='O';
// cout<<finish<<endl;
//c 多行短字符串,无空格隔开 & 字符串长度
// char buf[255];
// while(~scanf("%s",buf)){
// int len=strlen(buf);
// printf("printf: %s,end:%d",buf,len);
// }
// char finish[]={'D','O','N','E'};
// printf("%s",finish);
//c++ 一行一行字符串读入,长字符串有空格
// string str;
// char str[255];
// while(getline(cin,str)){
// cout<<"str: "<<str<<" len:"<<str.length()<<endl;
// }
// while(cin.getline(str,255)){
// cout<<"str: "<<str<<" len:"<<strlen(str)<<endl;
// }
// cout<<"DONE!"<<endl;
//c 一行一行字符串读入,长字符串有空格
// char buf[255];
// while(gets(buf)){
// printf("buf:%s\nlen:%d\n",buf,strlen(buf));
// }
// printf("%s","done!");
//输入,输出二维矩阵
// char arr[100][100];
// string line[100];
// for(int i=0;i<3;i++){//c++ cin,cout;c scanf,gets,printf
// cin.getline(arr[i],255);
// getline(cin,line[i]);
// gets(arr[i]);
// }
// cout<<endl;
// for(int i=0;i<3;i++){
// cout<<line[i]<<endl;
// printf("%s\n",arr[i]);
// }

//string与int互转
// string s="123";
// cin>>s;
// int a=atoi(s.c_str());
// float a=atof(s.c_str());
// int a=37847;
// string b=to_string(a);//to_string()对于参数为浮点数,返回的结果跟cout不一样
// cout<<b<<endl;
//字符串分割
// string s="you are great!";
// vector<string> res;
// split(s," ",res);
// for(string item:res)
// cout<<item<<endl;
}
// void split(string s,string separator,vector<string>& vec){
// int subStrPosStart=0;
// int separatorIdx=s.find(separator,subStrPosStart);
// while(separatorIdx!=string::npos){
// vec.push_back(s.substr(subStrPosStart,separatorIdx-subStrPosStart));
// subStrPosStart=separatorIdx+separator.length();
// separatorIdx=s.find(separator,subStrPosStart);
// }
// if(subStrPosStart!=s.length())
// vec.push_back(s.substr(subStrPosStart));
//
// }