很長時間沒有做了,也就很長時間沒有寫了,rating嘩嘩的往下掉啊 ,已經變綠了,這次三題掛了一個,a2Y,b1Y,
A
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
long long i,j,k,n,m;
cin>>n>>k;
m = k*2-1;
if(m>n)
{
long long x = (n+1)/2;
cout<<(k-x)*2<<endl;
}
else
cout<<m<<endl;
return 0;
}
B
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
using namespace std;
char str[1000010];
int main()
{
int i,j,k,n,num=0;
char s1[20],s2[20];
long long s=0;
cin>>str;
k = strlen(str);
for(i = 0 ; i < k ; i++)
{
if(i+5>k)
break;
if(str[i]=='h'&&i+5<=k)
{
int g=0;
for(j = i ; j < i+5 ; j++)
s1[g++] = str[j];
s1[g] = '\0';
if(strcmp(s1,"heavy")==0)
{
num++;
i+=4;
}
}
if(str[i]=='m'&&i+5<=k)
{
int g= 0;
for(j = i ; j < i+5 ; j++)
s2[g++] = str[j];
s2[g] = '\0';
if(strcmp("metal",s2)==0)
{
s+=num;
i+=4;
}
}
}
cout<<s<<endl;
return 0;
}
C 之後稍改了下 就A了
#include <iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
int i,j,k;
long long a,b,m,t,g=0;
cin>>a>>b>>m;
if(a>=m||b>=m)
{
cout<<"0\n";
return 0;
}
if(a<b)
{
t = a;
a = b;
b = t;
}
if(a>0&&b<0)
{
g = -b/a;
b = g*a+b;
}
long long s = a+b;
long long s1 = s;
long long num=1;
while(s<m)
{
long long k = max(a,b);
a = k;
b = s;
s = a+b;
num++;
if(s<=s1)
{
cout<<"-1\n";
return 0;
}
}
cout<<g+num<<endl;
return 0;
}