UVALive 4854 A Digital Satire of Digital Age
来源:互联网 发布:路由器mac地址有什么用 编辑:程序博客网 时间:2024/06/05 02:15
题意:给一张天平的图,通过每个字符的ASCII码的二进制表示算出它的重量,判断已给图中天平的状态是否正确。
分析:因为图中天平的状态只有三种,而且天平中的字符都是大写字母,并且都在同一行,所以计算重量时很简单,给26个字母的重量打表。
在计算天平中字符重量的同时,记录天平左右两个称的高度。一开始,我是检测到字母时记录高度,后来发现这样做就忽略了某个称空着的情况,于是改成当检测到第1列或第11列是‘/’时记录称的高度,因为描绘天平的形状的字符是有固定规律的。
最后分类讨论,给出输出。
#include <cstdio>#include <iostream>#include <algorithm>#include <string>#include <cstring>using namespace std;char a[10], b[10], tt[20];int w[26] = {9, 9, 10, 9, 10, 10, 11, 9, 10, 10, 11, 10, 11, 11, 12, 9, 10, 10, 11, 10, 11, 11, 12, 10, 11, 11};//记录(26个字母的重量 / 250)int main(){ int t, cnt; char ch; int ha, hb, cnta, cntb, suma, sumb; scanf("%d", &t); cnt = 1; a[7] = b[7] = '\0'; while(t--) { cnta = cntb = suma = sumb = ha = hb = 0; for(int i = 1; i <= 7; i++) { getchar(); for(int j = 1; j <= 18; j++) { scanf("%c", &ch); if (j == 1 && ch == '/') ha = i; if (j == 11 && ch == '/' ) hb = i; if(ch >= 65 && ch <= 90) { //printf("ch=%c\n", ch); if(j <= 7 && j >= 2) { a[++cnta] = ch; //ha = i; suma += w[ch - 'A']; } if(j >= 12 && j <= 17) { b[++cntb] = ch; //hb = i; sumb += w[ch - 'A']; } } } } scanf("%s", tt); //printf("ha:%d,hb%d\n", ha, hb); if((ha > hb && suma > sumb) || (ha < hb && suma < sumb) || (ha == hb && suma == sumb)) printf("Case %d:\nThe figure is correct.\n", cnt++); else { while(cnta <6) { a[++cnta] = '.'; } while(cntb <6) { b[++cntb] = '.'; } if(suma == sumb) { printf("Case %d:\n", cnt++); printf("........||........\n"); printf(".../\\...||.../\\...\n"); printf("../..\\..||../..\\..\n"); printf("./....\\.||./....\\.\n"); printf("/%s\\||/%s\\\n",a + 1,b + 1); printf("\\______/||\\______/\n"); printf("........||........\n"); } else if(suma < sumb) { printf("Case %d:\n", cnt++); printf(".../\\...||........\n"); printf("../..\\..||........\n"); printf("./....\\.||.../\\...\n"); printf("/%s\\||../..\\..\n",a + 1); printf("\\______/||./....\\.\n"); printf("........||/%s\\\n",b + 1); printf("........||\\______/\n"); } else if(suma > sumb) { printf("Case %d:\n", cnt++); printf("........||.../\\...\n"); printf("........||../..\\..\n"); printf(".../\\...||./....\\.\n"); printf("../..\\..||/%s\\\n", b + 1); printf("./....\\.||\\______/\n"); printf("/%s\\||........\n", a + 1); printf("\\______/||........\n"); } } }}
0 0
- UVALive 4854 A Digital Satire of Digital Age
- UVALive 4854 A Digital Satire of Digital Age
- A Digital Satire of Digital Age
- hust A Digital Satire of Digital Age
- UVA 4854 A Digital Satire of Digital Age(模拟)
- UVALive 2037 Digital River
- UVALive - 6269 Digital Clock 模拟
- Applicaton of Digital Watermarking
- 495A - Digital Counter
- A. Digital Counter
- UVALive 6269 Digital Clock --枚举,模拟
- UVALive 2037 Digital Rivers 【打表&二分】
- What is a Digital Signature?
- A. Vasya and Digital Root
- What is a Digital Signature?
- codeforces #495A# Digital Counter
- CodeForces 495A Digital Counter
- codeforces - 495A Digital Counter
- 图片下载-同步/异步(delegate和block)
- 网络故障之DHCP广播风暴------运维上看交换机的CPU占用率100%
- 在Eclipse中用JDBC连接mysql的问题
- 一个JavaScript实现的贷款计算器
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- UVALive 4854 A Digital Satire of Digital Age
- OJ的搭建
- 使用Spring的@Scheduled实现定时任务
- SimpleAdapter 支持的组件
- ZOJ 3209 Treasure Map (DLX精确覆盖问题)
- 腾讯2014年实习生招聘广州站offer经历(TEG-后台开发)
- JAVA实验一
- 黑马程序员——java基础日记——继承、接口
- 万能的自动化测试框架