本篇没有涉及很多算法,主要为一些模拟题,难度不大,具体实现代码可自行练习。
1.简单模拟
模拟题主要考察代码能力,简单模拟不涉及算法,完全只是根据题目描述来进行代码的编写。
-
HDU3361 ASCII (打印输出)
-
HDU4144 KFC -Z+W (最小排队时间)
-
HDU6023 Automatic Judge (AC时间)
2.图形输出
图形由若干字符组成。做法一般有两种:
①通过规律直接进行输出
②定义一个二维字符数组,通过规律填充之,然后输出整个二维数组
-
HDU1256 画8
-
HDU4218 IMBA? (画椭圆)
3.日期处理
注意细节
4.进制转换
5.字符串处理
这种类型题目较常见。可能实现逻辑较麻烦,需要注意细节和边界情况。
-
HDU4150 Powerful Incantation (字符串匹配)
-
HDU1736 美观化文字 (标点符号的转换)
#include <iostream>
#include <string>
using namespace std;
char s[1000000];
int main()
{
while(gets(s)){
int k=0;
int len=strlen(s);
for(int i=0;i<len;i++){
string t="";
t=t+s[i]+s[i+1];
if(t =="“"||t=="”")
k=!k;
else {
if(t==">>"){//一个标点占2个宽度
i++;
cout<<"》";
continue;
}
else if(t=="<<"){
i++;
cout<<"《";
continue;
}
}
if(s[i]=='"'){
if(k)
printf("”");
else
printf("“");
k=!k;
}
else if(s[i]==',') cout<<",";
else if(s[i]=='.') cout<<"。";
else if(s[i]=='?') cout<<"?";
else if(s[i]=='!') cout<<"!";
else cout<<s[i];
}
cout<<endl;
}
return 0;
}
-
HDU3363 Ice-sugar Gourd (分糖葫芦)
#include <iostream>
using namespace std;
char str[1000000];
int HT[1000000];
int main()
{
int n;
while(cin>>n&&n)
{
cin>>str;
if(n%2!=0)
{
cout<<"-1\n";
continue;
}
int t=0;
for(int i=0; i<n; i++)
{
if(str[i]=='H')
t++;
HT[i]=t;//到i位置有 t 个 H
}
//如果H的数量是奇数,那么无法将该字符串进行得分
if(t%2!=0)
{
cout<<"-1\n";
continue;
}
//如果在字符串的中间处统计的H的数量等于H总数量的一半,切割位置就是n/2
if(HT[n/2-1]==t/2)
{
printf("1\n%d\n",n/2);
continue;
}
//中间位置的H 的数量少于字符串的H的总数量
//就从字符串的中间位置开始,
//直到找到H的数量满足字符串总数量的一半的位置
for(int i=1; i<n/2; i++)
{
if ((HT[i+n/2-1]-HT[i-1])==t/2) // (i-1)+n/2 与 i-1
{
printf("2\n%d %d\n",i,i+n/2);
break;
}
}
}
return 0;
}