B - Ancient Prophesy CodeForces - 260B

第二次比赛,我感受到了我心态的问题,还有思维的缺陷把。 容易钻进死胡同。 这道题题意很简单,就是要去找符合条件的字符串。

/*If I get TLE , it is good.If I get AC,it's NICE !*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const int MAXN=1e7+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
map <string,int> temp;
char str[MAXN];
int is(char x)
{
    if(x>='0'&&x<='9')return 1;
    else return 0;
}
int main(void)
{
    temp.clear();
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1; i<=len-9; i++)
    {
        if(  is(str[i]) &&is(str[i+1]) &&str[i+2]=='-' &&is(str[i+3]) && is(str[i+4])  && str[i+5]=='-' && is(str[i+6]) && is(str[i+7] )&&  is(str[i+8]) &&  is(str[i+9])  )
        {
            int nian=(str[i+9]-'0')*1+(str[i+8]-'0')*10+(str[i+7]-'0')*100+(str[i+6]-'0')*1000;
            int yue=(str[i+3]-'0')*10+str[i+4]-'0';
            int ri=(str[i]-'0')*10+str[i+1]-'0';
            if(yue==0 || ri==0) continue;
            if(yue==4 ||yue==6 ||yue==9 ||yue==11  )
            {
                if(ri==31)  continue;
            }
            if(nian<2013 || nian>2015)  continue;
            if(yue>12 || yue <1)  continue;
            if(yue==2)
            {
                if(ri>=29 || ri ==0)
                    continue;
            }
            string s;
            //s.resize(15);
            //s.clear();
            int k=i;
            for(int j=0;j<=9;j++)
            {
                //s[j]=str[k++];
                s += str[k++];
                //printf("??? %d\n",s.size());
            }
            //cout << s <<endl;
            //cout <<temp[s] << endl;
            ++temp[s];
            //cout <<temp[s] << endl;
        }
    }

    int maxx=-1;
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx < it->second) maxx = it->second ;
    }
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx == it->second) {(cout << it->first<<endl) ; return 0;}
    }
}

要注意的地方:
1.对于年份,注意闰年和平年对2月造成的影响;
2.对于月份,如果大于12,或者小于1,continue;
3.对于日,分类在闰年和平年的情况下,如果是闰年,2月如果大于30 || 小于1 continue; 其他月份分30,和31天;平年同理

还有对map容器遍历的过程,今天还是和学长请教了,实在不想看博客,静不下心来的表现.(对MAP的遍历还要多敲几遍,熟悉套路)

for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx < it->second) maxx = it->second ;
    }
    for(map<string,int>::iterator it= temp.begin();it!=temp.end();it++)
    {
        if(maxx == it->second) {(cout << it->first<<endl) ; return 0;}
    }

这场比赛下来,我学到了什么
1.对于思维题,一定要活跃一点。
2.如果做不出来,可以先放一放,看下面的题,不要想着前面的题又做下面的题,不然一题都做不出来。

// 你TM就是个彩笔,大彩笔,还不努力

可以,以下是一个简单的示例代码,可以打印出两千常用汉字及其语义和笔画: ```java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class ChineseCharacter { public static void main(String[] args) throws IOException { String fileName = "chinese_characters.txt"; // 存放两千常用汉字的文件路径 Map<String, String[]> characterMap = new HashMap<>(); // 存放汉字及其语义和笔画的Map BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; while ((line = br.readLine()) != null) { String[] arr = line.split("\t"); if (arr.length == 3) { String[] value = new String[2]; value[0] = arr[1]; // 语义 value[1] = arr[2]; // 笔画 characterMap.put(arr[0], value); } } br.close(); System.out.println("汉字\t语义\t笔画"); for (Map.Entry<String, String[]> entry : characterMap.entrySet()) { StringBuilder sb = new StringBuilder(); sb.append(entry.getKey()).append("\t"); String[] value = entry.getValue(); sb.append(value[0]).append("\t"); sb.append(value[1]); System.out.println(sb.toString()); } } } ``` 以上代码中,需要先准备一个文件,文件中每行存放一个汉字及其语义和笔画,用制表符`\t`分隔。示例文件内容如下: ``` 一 one 1 乙 second; 2nd heavenly stem 1 二 two 2 十 ten 2 丁 nail; small cube-shaped object; pellet, grain; cubic meter; fourth of 10 Heavenly Stems; surname Ding 2 厂 cliff; factory, workshop; depot; yard, courtyard; surname Chang 2 七 seven 2 卜 divine; prophesy; observe 2 ``` 执行以上代码后,将会打印出两千常用汉字及其语义和笔画,示例输出如下: ``` 汉字 语义 笔画 佚 lose; forget; miss; enjoy; at ease 7 充 fulfill; fill; supply; satisfy; plug; be full; be used up; be sufficient 6 亘 extend; cover; range over 8 仆 fall forward; lie prostrate; servant; pawn; fall forward; lie prostrate; servant; pawn 5 炎 flame; blaze; inflammation; surname Yan 8 井 well; neat; orderly 4 ``` 需要注意的是,以上代码只是一个简单的示例,实际中需要更加完善的数据集来包含所有的汉字及其语义和笔画。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值