HDU 4140
来源:互联网 发布:怎样使用网络电视 编辑:程序博客网 时间:2024/05/21 14:46
// env:gcc
#include <stdio.h>#include <stdlib.h>#include <string.h>x = 0;nc = 0;long long res;sg,cef,idx;long long pw(int x, int a);main(){ int t; for(scanf("%d", &t); t--;) run();}run(int c){ scanf("%d", &x); result(); printf("Case #%d: %I64d\n", ++nc, res);}peek(){ int c = getchar(); ungetc(c, stdin); return c;}skip(){ int c; while((c=getchar())<=32); ungetc(c, stdin);}expect(int ch){ if(peek()==ch) return getchar(),1; return 0;}result(){ int ans = 0, ch; res = 0; skip(); do{ term(); ch = peek(); }while(ch=='+'||ch=='-');}term(){ sign_(); coef_(); index_(); res += (~sg?-cef:cef)*pw(x, idx);}sign_(){ sg = expect('-') ? -1 : expect('+'), 1;}coef_(){ if(peek()>='0' && peek()<='9') scanf("%d", &cef); else cef=1;}index_(){ if (expect('X')) if (expect('^')) scanf("%d", &idx); else idx=1; else idx = 0;}long long pw(int x, int a){ long long d=1, b=x; while(a){ if(a&1) d*=b; b*=b; a>>=1; } return d;}
也木有蛮多好说的 把文法想清楚,翻译一遍就行了
- HDU 4140
- hdu 4140 模拟
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- C++ FAQs学习笔记
- 一些C/C++的实用HOWTO备忘
- little endian和big endian
- 《Optimizing for SSE: A Case Study》的读后感
- C语言里求类型BIT数
- HDU 4140
- SUBPIXEL精度
- 今天学到一个高招
- 切换到64BIT VISTA后VS不能DEBUG的问题
- OpenGL像素处理流程
- (转载)一篇有趣的文章
- 关于Wavefront OBJ文件格式的资料
- FPGA学习笔记4-VHDL
- Ant的几个要点