1. 程式人生 > >pat 甲級 1100(模擬題)

pat 甲級 1100(模擬題)

題目連結:https://pintia.cn/problem-sets/994805342720868352/problems/994805367156883456

思路:(1)整行輸入,分別對數字和字串處理

(2)對字串要判斷是一串還是兩串,然後判斷是十位還是個位

(3)對數字判斷十位和個位存在與否,注意:這裡第一次出錯了,因為整13是tam,不是tam tret。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
string b1[20]={"tret","jan","feb","mar","apr","may",
"jun","jly","aug","sep","oct","nov","dec"};
string b2[20]={"","tam","hel","maa","huh","tou","kes",
"hei","elo","syy","lok","mer","jou"};
int main(void)
{
	int n,i,ans,j;
	cin>>n;
	getchar();
	string s1;
	for(i=0;i<n;i++)
	{
		getline(cin,s1);
		if(s1[0]>='0'&&s1[0]<='9')
		{
			ans=0;
			for(j=0;j<s1.length();j++)
			ans=ans*10+s1[j]-'0';
			int t1=ans/13,t2=ans%13;
			if(t1==0)
				cout<<b1[t2]<<endl;
			else
			{
				if(t2) cout<<b2[t1]<<" "<<b1[t2]<<endl;
				else cout<<b2[t1]<<endl;
			}
		}
		else
		{
			string s2="",s3="";
			int fg=0;
			for(j=0;j<s1.length();j++)
			if(s1[j]==' ')
			{
				fg=1;break;
			}
			if(fg==0)
			{
				int pt=0;
				for(j=0;j<13;j++)
				if(s1==b1[j])
				{
					cout<<j<<endl;pt=1;break;
				}
				if(pt==0)
				{
					for(j=1;j<13;j++)
				    if(s1==b2[j])
				    {
					cout<<j*13<<endl;break;
				    }
				}
			}
			else
			{
				ans=0;
				for(j=0;j<s1.length()&&s1[j]!=' ';j++) s2+=s1[j];
				for(j++;j<s1.length();j++) s3+=s1[j];
				for(j=1;j<13;j++)
				if(s2==b2[j])
				{
					ans+=j*13;break;
				}
				for(j=0;j<13;j++)
				if(s3==b1[j])
				{
					ans+=j;break;
				}
				cout<<ans<<endl;
			}
		}
	}
	return 0;
}