本文共 1362 字,大约阅读时间需要 4 分钟。
一个小模拟,计算表达式的值,一直到最后没做出来,检查好半天才发现就是一个字幕结束符标错了!!!!虽然多做上这一道题并不会有多大优势,但是还是会觉得因为这一点点错误就没坐上特比特别的可惜,不要不在意这一点点马虎,这就是你没有实力的表现,实力就是能力加细节!!!吸取教训
HDU 3347#include #include #include #include #include using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { int n; string s; map mp; mp.clear(); scanf("%d",&n); for(int i=0;i >s; char a; int value; scanf(" %c ",&a); scanf("%d",&value); mp[s]=value; } getchar(); char ano[500]; char tmp[30]; gets(ano); int k=1; int len=strlen(ano); long long sum=0; int first=0; int haha=0; for(int i=0;i ='a'&&ano[i]<='z') { //puts("a3"); for(int j=i;;j++) { if(ano[j]==' ') {tmp[haha]='\0';i=j+1;break;} //这里把haha写成j了!!!! else if(ano[j]>='a'&&ano[j]<='z') tmp[haha++]=ano[j]; } if(k==1) sum+=mp[tmp]; else if(k==2) sum-=mp[tmp]; haha=0; } else if(ano[i]=='-') { //puts("a4"); int mm=0; for(int j=i;;j++) { if(ano[j]==' ') {i=j+1;break;} else if(ano[j]>='0'&&ano[j]<='9') mm=mm*10+(ano[j]-'0'); } mm=-mm; if(k==1) sum+=mm; else if(k==2) sum-=mm; } else if(ano[i]>='0'&&ano[i]<='9') { //puts("a5"); int tmp=0; for(int j=i;;j++) { if(ano[j]==' ') {i=j+1;break;} else if(ano[j]>='0'&&ano[j]<='9') tmp=tmp*10+(ano[j]-'0'); } if(k==1) sum+=tmp; else if(k==2) sum-=tmp; } } printf("%lld\n",sum); } return 0;}/*53aa = 7bb = -0-10 - -9 - bb + aa = ?*/
转载地址:http://lcbci.baihongyu.com/