输入输出那些事

  1. cin cout
  2. scanf() printf()
  3. 格式:
  4. cin>> cout<<
  5. 慢(关闭同步流)
  6. ios::sync_with_stdio(false);
  7. can.tie(0);
  8. scanf("%d",&x);
  9. printf("%d",&x);高
  10. 效率:数量量在万级以下区别不明显

2

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N =105;
  4. char arr[105];
  5. int main(){
  6. int n;
  7. cin>>n;
  8. char x;
  9. for(int i=1;i<=n;i++){
  10. scanf("%c",&x);
  11. arr[i] =x;
  12. }
  13. for(int i=n;i>0;i--){
  14. int idx =arr[i]+1;
  15. if(idx % 2 ==0){
  16. printf("%d ",i);
  17. }
  18. }
  19. return 0;
  20. }

3

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int x;
  5. if(cin>>x) cout<<"yes";
  6. else cout<<"no";
  7. return 0;
  8. }

4课堂练习三 (结束符也符合容器类型判断)

  1. int n;
  2. while(cin >> n && n !=0 ){
  3. }

5

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int p,x,sum;
  5. p=1;
  6. x=15;
  7. sum=x;
  8. do{
  9. p++;
  10. x+=2;
  11. sum+=x;
  12. }while(sum!=312);
  13. // cout<<x<<endl;
  14. // cout<<p<<endl;
  15. printf("%d\n%d\n",x,p);
  16. return 0;
  17. }