第一类——模拟题

  做了这么久才弄完第一类的题目,不是很难,相反是比较容易的一类题目。就怪自己太赖了,老是想着偷偷看电视。以后可不能这样了。虽说把PPS卸载掉不是什么绝对有用的措施,但也可以暂时缓和一下。下面是我自己做的代码,除了火星A+B以外,都被AC了。总结:思维比较混乱,有时候想法太多,想得也太复杂了。总觉得别人做的答案真是恰到好处,多一行不多,少一行不少。就和做菜下作料一样,得好好修炼才行....

2005年  A+B(http://acm.hdu.edu.cn/showproblem.php?pid=1228

 #include #include using namespace std; char chkey[10][10] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; int ChangeAtoD(char str[]) { int i; for(i=0;i<=9;i++) { if(strcmp(str,chkey[i]) == 0) return i; } return -1; } int main() { char inch[10]; int a,b; while(true) { a = 0; while(scanf("%s",inch)&&(strcmp(inch,"+") != 0)) a = a*10 + ChangeAtoD(inch); b = 0; while(scanf("%s",inch)&&(strcmp(inch,"=") != 0)) b = b*10 + ChangeAtoD(inch); if((a==0)&&(b==0))break; printf("%d/n",a+b); } return 0; }

 

2006年 还是A+B(http://acm.hdu.edu.cn/showproblem.php?pid=1229)
#include #include using namespace std; int getK(int n,int k) { int i=1,j=0; while(k--) i*=10; j = n%i; j = j/(i/10); return j; } int main() { const int res = -1; int a,b,c; bool flg; while(scanf("%d%d%d",&a,&b,&c)) { if(a==0&&b==0)break; flg = true; for(int i=1;i<=c;i++) { if(getK(a,i) != getK(b,i)) { flg = false;break; } } if(!flg) { printf("%d/n",a+b); } else cout<

2006年 火星A+B(http://acm.hdu.edu.cn/showproblem.php?pid=1230)

 (在机子上运行没错,放上去就错了!到现在还没找出错在哪里!哎~~~)

#include #include const int num = 30; int primeKey[num]; int countPrime; //素数及个数 int a[num],b[num]; //存放两个数 int countA ,countB; //两个数的的个数 int c[num],countC; void Prime() //筛选出素数 { int i,k; bool flg; countPrime = 0; for(i=2;i<=1000&&countPrime=0;i--) { if(c[countC]+a[i] >= primeKey[countC]) { c[countC] = c[countC]+a[i]-primeKey[countC]; countC++; c[countC] = 1; } else { c[countC] = c[countC]+a[i]; countC++; } } } void Add() { int i,j; memset(c,0,sizeof(c)); i = countA-1; j = countB-1; while(j>=0&&i>=0) { if(c[countC]+a[i]+b[j] >= primeKey[countA-i-1]) { c[countC] = c[countC]+a[i]+b[j]-primeKey[countA-i-1]; countC++; c[countC] = 1; } else { c[countC] = c[countC]+a[i]+b[j]; countC++; } j--;i--; } if(i>=0)Cadd(a,i); else if(j>=0)Cadd(b,j); } int main() { Prime(); while(true) { countA=countB=countC=0; Input(); if(IsZero(a,countA)&&IsZero(b,countB))break; Add(); printf("%d",c[countC]); for(int i=countC-1;i>=0;i--) printf(",%d",c[i]); printf("/n"); } return 0; }

2006年 统计同成绩学生人数(http://acm.hdu.edu.cn/showproblem.php?pid=1235

#include int a[1000],ai,score; int main() { int count; while(scanf("%d",&ai)&&ai!=0) { count = 0; for(int i=0;i

2006年 简单计算器(http://acm.hdu.edu.cn/showproblem.php?pid=1237

#include #include double od[100]; //操作数 int op[100]; //操作符 int odi,opi; int prior[4][4] = { 1,1,-1,-1, 1,1,-1,-1, 1,1,1,1, 1,1,1,1 }; void Input() { int x; char ch1,ch2; odi = opi = 0; memset(od,-1,sizeof(od)); memset(op,-1,sizeof(op)); while(true) { scanf("%d%c",&x,&ch1); od[odi++] = x; if(ch1 != ' ')break; scanf("%c%c",&ch2,&ch1); if(ch2 == '+')op[opi++] = 0; else if(ch2 == '-')op[opi++] = 1; else if(ch2 == '*')op[opi++] = 2; else if(ch2 == '/')op[opi++] = 3; else printf("input error!/n"); } } bool IsZero() { if(odi==1&&od[0] == 0)return true; return false; } void Switch(int index) { for(int i=index;i 1) { if(prior[op[0]][op[1]] == 1) { switch(op[0]) { case 0:od[0] = od[0]+od[1]; break; case 1:od[0] = od[0]-od[1];break; case 2:od[0] = od[0]*od[1];break; case 3:od[0] = od[0]/od[1];break; } Switch(1); odi--;opi--; } else if(prior[op[0]][op[1]] == -1) { switch(op[1]) { case 0:od[1] = od[1]+od[2];break; case 1:od[1] = od[1]-od[2];break; case 2:od[1] = od[1]*od[2];break; case 3:od[1] = od[1]/od[2];break; } Switch(2); odi--;opi--; } } if(opi==1) { switch(op[0]) { case 0:od[0] = od[0]+od[1]; break; case 1:od[0] = od[0]-od[1];break; case 2:od[0] = od[0]*od[1];break; case 3:od[0] = od[0]/od[1];break; } } printf("%.2lf/n",od[0]); } int main() { while(true) { Input(); if(IsZero())break; Calculate(); } return 0; }

 

2007年 最小长方形(http://acm.hdu.edu.cn/showproblem.php?pid=1859)
#include int main() { int x,y; int x1,y1,x2,y2; bool flg; while(true) { flg = true; while(scanf("%d %d",&x,&y)&&(x!=0||y!=0)) { if(flg) { x1=x2=x;y1=y2=y; flg = false; } if(x < x1) x1 = x; if(x > x2) x2 = x; if(y < y1) y1 = y; if(y > y2) y2 = y; } if(flg)break; printf("%d %d %d %d/n",x1,y1,x2,y2); } return 0; }

 

2007年 统计字符(http://acm.hdu.edu.cn/showproblem.php?pid=1860

#include #include const int Ab = 65; const int ab = 71; int c[5]; int n[53]; int ci; void Switch(char ch) { if(ch == ' ')c[ci++] = 52; else if(ch>64&&ch<91)c[ci++] = ch - Ab; else if(ch>96&&ch<123)c[ci++] = ch - ab; else printf("input error!"); } void SwitchTo(char ch) { if(ch == ' ')n[52]++; else if(ch>64&&ch<91)n[ch - Ab]++; else if(ch>96&&ch<123)n[ch - ab]++; else printf("input error!"); } int main() { char ch; int cr; while(scanf("%c",&ch)&&ch!='#') { ci = 0; memset(c,-1,sizeof(c)); memset(n,0,sizeof(n)); Switch(ch); while(scanf("%c",&ch)&&ch!='/n') { Switch(ch); } while(scanf("%c",&ch)&&ch!='/n') { SwitchTo(ch); } for(int i=0;i

 

2007年 游船出租(http://acm.hdu.edu.cn/showproblem.php?pid=1861)
#include struct Time { int hour; int minute; }; struct Boat { int start; Time sTime; }; Boat boats[100]; int boati=0; void InitBoat() { for(int i=0;i<100;i++) { boats[i].start = 0; boats[i].sTime.hour = 0; boats[i].sTime.minute = 0; } } int main() { double times = 0,timeSum = 0; int retime; int n,h1,m1; char ch; InitBoat(); while(scanf("%d",&n)&&n != -1) { scanf(" %c %d:%d",&ch,&h1,&m1); //注意,就是因为这个才出错的 if(n != 0) { if(!boats[n].start&&ch == 'E')continue; //过滤掉没有开始,就有结束的 if(boats[n].start&&ch == 's')continue; //过滤掉已经开始,又要开始的 if(ch == 'S') { boats[n].sTime.hour = h1; boats[n].sTime.minute = m1; boats[n].start = 1; } else if(ch == 'E') { times = (h1-boats[n].sTime.hour)*60+(m1-boats[n].sTime.minute); timeSum +=times; boati++; boats[n].start = 0; } else printf("input error"); } else { if(boati==0) { printf("0 0/n"); } else { if((timeSum/boati)-(int)(timeSum/boati)>=0.5) { retime = (int)(timeSum/boati)+1; } else retime = (int)(timeSum/boati); printf("%d %d/n",boati,retime); } boati = 0; timeSum = 0; InitBoat(); } } return 0; }

你可能感兴趣的:(ACM)