POJ1008

题目链接

模拟题,一牵扯到字符串我整个人都不好了,百度了一下,我擦,原来string是扩展的一种类,所以printf和scanf这两个函数就不能直接控制string了。

如果执意要使用printf和scanf那么就要这样:

1 string a;
2 a.resize(100);
3 scanf("%s",&a[0]); //不过不知道是不是真的有用
4 
5 printf("%s",a.c_str());//是不是很麻烦啊,所以还是不要这么用了,我觉得cin和cout完全够用了

这里面还牵扯到了字符串映射到数值的问题,所以用到了map

问题主要出在了输入输出(也就是字符串)以及计算上面,以后还是要多做题多改进。

附上我滴代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<map>
 4 #include<cstring>
 5 using namespace std;
 6 map<string,int>hmonth;
 7 char *tmonth[]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban",
 8                 "eznab","canac","ahau"};
 9 
10 int main()
11 {
12     hmonth["pop"]=1;hmonth["no"]=2;hmonth["zip"]=3;hmonth["zotz"]=4;hmonth["tzec"]=5;hmonth["xul"]=6;hmonth["yoxkin"]=7;
13     hmonth["mol"]=8;hmonth["chen"]=9;hmonth["yax"]=10;hmonth["zac"]=11;hmonth["ceh"]=12;hmonth["mac"]=13;hmonth["kankin"]=14;
14     hmonth["muan"]=15;hmonth["pax"]=16;hmonth["koyab"]=17;hmonth["cumhu"]=18;hmonth["uayet"]=19;
15     int n;
16     scanf("%d",&n);
17     cout<<n<<endl;
18     while(n--){
19         int day,year;
20         scanf("%d",&day);
21         getchar();
22         getchar();
23         string month;
24         cin>>month;
25         int num_month=hmonth[month];
26         scanf("%d",&year);
27         int htotdays=year*365+(num_month-1)*20+day;
28         year=htotdays/260;
29         day=htotdays%260;
30         month=tmonth[day%20];
31         day=day%13+1;
32         printf("%d %s %d\n",day,month.c_str(),year);
33     }
34     return 0;
35     }

 

posted @ 2015-04-25 22:36  JimmyLin^_^  阅读(156)  评论(0编辑  收藏  举报