您的位置:首页 > 其它

Codeforces 174B【模拟构造】

2016-12-06 16:46 435 查看
题意:

给你一个串只有小写字母和点,让你构造前缀是1-8,后缀是1-3长度的文件名;

思路:

那么以"."作为分割点,把字符串都拿出来,然后

首段长度<=8 OK;

中间<=11 OK;

尾段<=3 OK;
否则都不行;

啊,水题啊,wa了一次,T了一次,神TM都是数据开小了,

一个是4e5写成5e4。。。

一个是不满足的情况可能会很长,才开了。。。25...

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;

const int N=4e5+10;
struct asd
{
int length;
char tep[50];
};
int num;
asd q
;
char s
;

char ans
[50];
char temp
;

int main()
{
int temp_num;
scanf("%s",s);
int len=strlen(s);
bool flag=false;
num=0;
temp_num=0;
for(int i=0; i<len; i++)
{
if(s[i]=='.')
{
if(!flag)
{
if(temp_num>8||!temp_num)
{
puts("NO");
return 0;
}
temp[temp_num]='\0';
strcpy(q[num].tep,temp);
q[num].length=temp_num;
num++;
flag=true;
}
else
{
if(temp_num>11||temp_num<2)
{
puts("NO");
return 0;
}
temp[temp_num]='\0';
strcpy(q[num].tep,temp);
q[num].length=temp_num;
num++;
}
temp_num=0;
}
else
temp[temp_num++]=s[i];
}
if(!temp_num||temp_num>3||!flag)
{
puts("NO");
return 0;
}
temp[temp_num]='\0';
strcpy(q[num].tep,temp);
q[num].length=temp_num;
num++;
int kp=0;
int ans_num=0;
int pp=0;
for(int i=1;i<num;i++)
{
pp=0;
for(int j=kp;j<q[i-1].length;j++)
ans[ans_num][pp++]=q[i-1].tep[j];
ans[ans_num][pp++]='.';
if(q[i].length>3)
kp=3;
else
kp=1;
if(i==num-1)
kp=q[i].length;
for(int j=0;j<kp;j++)
ans[ans_num][pp++]=q[i].tep[j];
ans[ans_num][pp]='\0';
ans_num++;
}
puts("YES");
for(int i=0;i<ans_num;i++)
printf("%s\n",ans[i]);
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: