UVaOJ 10878 - Decode the tape
来源:互联网 发布:浙江省网络监管服务网 编辑:程序博客网 时间:2024/06/06 07:26
//version2:蠢方法#include <cstdio>#include <cstring>using namespace std;char buf[15];int main(int argc, char *argv[]){fgets(buf, sizeof(buf), stdin);while(fgets(buf, sizeof(buf), stdin) && buf[0] != '_'){char ch = 0;if(buf[2] == 'o'){ch += 64;}if(buf[3] == 'o'){ch += 32;}if(buf[4] == 'o'){ch += 16;}if(buf[5] == 'o'){ch += 8;}if(buf[7] == 'o'){ch += 4;}if(buf[8] == 'o'){ch += 2;}if(buf[9] == 'o'){ch += 1;}printf("%c", ch);}return 0;}
/********************************* * 日期:2013-5-3 * 作者:SJF0115 * 题号: 10878 - Decode the tape * 来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1819 * 结果:AC * 来源:UVA * 总结: **********************************/ #include <stdio.h> #include <string.h> int c[] = { 0, 0, 64, 32, 16, 8, 0, 4, 2, 1, 0}; //这个好~ int main() { char str[15]; int value,i; //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin); gets(str); while(gets(str) && str[0] != '_'){ value = 0; int len = strlen(str); for(i = 2;i < len;i++){ if(str[i] == 'o'){ value += c[i]; } } printf("%c",value); } }
当然要思考程序写得优不优雅,能不能通用,但是很多时候没有必要。
#include<stdio.h>int main(){ char c; int bin=0,i=0; while((c=getchar())!=EOF) { if(c=='\n') { if(i==8) { putchar(bin); i=0; } bin=0; } else { if(c==' ') { bin=bin*2; i++; } else if(c=='o') { bin=bin*2+1; i++; } } } return 0;}
以下一段是错误的代码,提交这类代码到OJ会导致Runtime Error!
因为我想要把结果存下来然后一次性全部显示,会出现一个问题:不知道为什么,大概就是因为数组越界,然后导致Runtime Error……
然后我就学乖了,学会用上一段代码,得出一个结果就输出一个。虽然,在命令行下,显示的结果很不好看,input和output混在一起,但是是可以通过OJ的。
#include <cstdio>#include <cstring>using namespace std;char ans[500];char buf[15];int mul[7];int main(int argc, char *argv[]){for(int i = 0; i < 7; ++i){mul[i] = 1 << i;}gets(buf);int n = 0;while(gets(buf) && buf[0] != '_'){ans[n] = 0;if(buf[2] == 'o'){ans[n] += mul[6];}if(buf[3] == 'o'){ans[n] += mul[5];}if(buf[4] == 'o'){ans[n] += mul[4];}if(buf[5] == 'o'){ans[n] += mul[3];}if(buf[7] == 'o'){ans[n] += mul[2];}if(buf[8] == 'o'){ans[n] += mul[1];}if(buf[9] == 'o'){ans[n] += mul[0];}++n;}ans[n] = '\0';printf("%s", ans);return 0;}
0 0
- UVaOJ 10878 - Decode the tape
- UVaOJ 10878 - Decode the tape
- UVAOJ 10878 ——Decode the tape 模拟
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- 10878 - Decode the tape
- UVa 10878 - Decode the tape
- uva 10878 Decode the tape
- dataGridView添加行号
- 关闭android程序里所有的activity
- Cocos2d-x 3.0 使用TinyXml 解析XML文件
- How Tomcat works之第九章 会话管理
- NoSQL中的行存储与列存储
- UVaOJ 10878 - Decode the tape
- C# 基于密码的身份验证报错问题System.Net.NetworkCredential
- 指针知识梳理7- 函数指针
- Django自定义过滤器filter
- Leetcode: Scramble String
- In,内链接和空值
- OpenOffice 编译日志
- c 语言编译器 (32bit测试)对整数类型long long截断
- C语言结构体定义