输入输出那些事
cin cout
scanf() printf()
格式:
cin>> cout<<
慢(关闭同步流)
ios::sync_with_stdio(false);
can.tie(0);
scanf("%d",&x);
printf("%d",&x);高
效率:数量量在万级以下区别不明显
2
#include <bits/stdc++.h>
using namespace std;
const int N =105;
char arr[105];
int main(){
int n;
cin>>n;
char x;
for(int i=1;i<=n;i++){
scanf("%c",&x);
arr[i] =x;
}
for(int i=n;i>0;i--){
int idx =arr[i]+1;
if(idx % 2 ==0){
printf("%d ",i);
}
}
return 0;
}
3
#include <bits/stdc++.h>
using namespace std;
int main(){
int x;
if(cin>>x) cout<<"yes";
else cout<<"no";
return 0;
}
4课堂练习三 (结束符也符合容器类型判断)
int n;
while(cin >> n && n !=0 ){
}
5
#include<bits/stdc++.h>
using namespace std;
int main(){
int p,x,sum;
p=1;
x=15;
sum=x;
do{
p++;
x+=2;
sum+=x;
}while(sum!=312);
// cout<<x<<endl;
// cout<<p<<endl;
printf("%d\n%d\n",x,p);
return 0;
}