由于突然到来的cccc选拔,以及各种事情,预计第13次ccf认证之前,只能将刷题记维持在05了,明天做一套最新题,今年再加一套练手就没什么时间了,加油吧
这套题似乎难度不小,前三题问题倒是不大,1h ak
先看看前三题
201509-1 数列分段
思路:按顺序将连续相同数字分成一段,水题,遍历跑一遍就好了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e5+10;
int main()
{
int n,a,b,num;
while(cin >> n)
{
num = 1;
cin >> a;
while(--n)
{
cin >> b;
if(b!=a)
{
a = b;
num++;
}
}
cout << num << endl;
}
return 0;
}
201509-2 日期计算
思路:要求求某一年的特定天是哪天,首先判断个平闰年,然后从元旦开始数就好了,注意预处理一下每个月日数会方便很多
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 1e5+10;
bool run(int y)
{
if((y%4==0&&y%100!=0)||y%400==0)
{
return true;
}
else
{
return false;
}
}
int main()
{
int y,d;
while(cin >> y >> d)
{
int mo,da;
int m[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
if(run(y))
{
m[1]++;
}
mo = 1;
while(d)
{
if(d>m[mo-1])
{
d -= m[mo-1];
mo++;
}
else
{
da = d;
d = 0;
}
}
cout << mo << endl << da << endl;
}
return 0;
}
201509-3 模板生成系统
思路:这就是个标准的ccf第三题大模拟,由于不考虑递归,其实没什么小细节,就是靠自己的细心和代码能力喽
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const int maxn = 110;
string web[maxn];
map<string, string> sig;
int main()
{
int m,n;
while(cin >> m >> n)
{
getchar();
for(int i=0;i<m;i++)
{
getline(cin,web[i]);
}
while(n--)
{
string temp;
getline(cin,temp);
int len = temp.length();
int pos = 0;
while(pos<len&&temp[pos]!=' ')
{
pos++;
}
string name;
name = temp.substr(0,pos);
sig[name] = temp.substr(pos+2,len-pos-3);
}
for(int i=0;i<m;i++)
{
int len = web[i].length();
int pos0 = 0;
while(pos0 < len)
{
int pos = pos0;
while(pos<len-1&&(web[i][pos]!='{'||web[i][pos+1]!='{'))
{
pos++;
}
if(pos == len-1)
{
pos++;
}
for(int j=pos0;j<pos;j++)
{
cout << web[i][j] ;
}
if(pos<len-1)
{
int pos1 = pos+3;
int pos2 = pos1;
while(pos2<len&&web[i][pos2]!='}')
{
pos2++;
}
pos2 -= 2;
int pos3 = pos2 + 3;
string re = web[i].substr(pos1,pos2-pos1+1);
cout << sig[re];
pos0 = pos3 + 1;
}
else
{
pos0 = pos;
}
}
cout << endl;
}
}
return 0;
}