codeforces之4.1学习记录

记录一些之前没见过的代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 2000000000ll
#define SIZE 100000ll
#define pb push_back
//#define fin cin
int main()
{
    ifstream fin("input.txt",ios::in);
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
  cout<<setprecision(10);
  cout<<fixed;
  int n;
  string a,b;
  cin>>n>>a>>b;
  int k=0;
  int d[n];
  for(int i=0;i<n;i++)
  {
    d[i]=b[i]-a[i];
  }
  for(int i=0;i<n-1;i++)
  {
    if(d[i]%2==1)
    {
      d[i]--;
      d[i+1]+=26;
    }
    if(d[i+1]<0)
    {
      d[i]-=2;
      d[i+1]+=26*2;
    }
    d[i]/=2;
  }
  d[n-1]/=2;
  string out="";
  for(int i=n-1;i>-1;i--)
  {
    //cout<<d[i]<<" ";
    if(a[i]+d[i]>'z')
    {
      d[i-1]++;
      char o = a[i]+d[i]-26;
      out+=o;
    }else
    {
      char o = a[i]+d[i];
      out+=o;
    }
  }
  reverse(out.begin(),out.end());
  cout<<out;
}
e题代码

1.ifstream fin("input.txt",ios::in);

定义一个来自于文件input.txtt的输入流,用ios::in方式 打开,in方式表示要读取文件,文件不存在的话,不建立文件,而是得到一个空的ifstream对像所以一般程序中会有这样的写法:ifstream fin("D:\\studf.txt",ios::in)if(fin!=NULL)......

2.ios_base::sync_with_stdio(false);

这个语句能使cin的输入更快

cin,cout速度慢,是因为先把要输出的东西存入缓冲区,再输出,导致效率降低,而这段ios_base::sync_with_stdio(false)可以来打消iostream的输入输出缓存,可以节省许多时间,使效率与scanf与printf相差无几

3.减少cin,cout时间

ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

4.控制格式输入输出的函数:setprecision(10);

5.reverse()反转字符串

#include<algorithm>

reverse(a,a+len);

6.找最大值最小值函数

max_element()函数和min_element()函数

string s;

char maxchar = *max_element(s.begin(), s.end()) ;

或者是

int a[n];

int maxn = *max_element(a,a+n) ;

7.set<char>(s.begin(), s.end()).size() == s.length();

string s;

set<char>(s.begin(), s.end()).size() == s.length();

意思是设一个char型的set集合

 

转载于:https://www.cnblogs.com/Aiahtwo/p/10639999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值