UVA10878 - Decode the tape
# 问题描述
从输入的一系列字符中,找出规律,从而转换后输出相应字符串。
# 思路
将'o'看成1,‘ ’看成0,从而一行组成一串二进制数值,将这二进制转换成ascII值并比较时发现与输出的字符一致。 通过数组相应数据能够更快解决题目。
# 代码
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
char a[]={0,0,64,32,16,8,0,4,2,1,0};
char s[30];
int ans;
gets(s);
while(gets(s)&&s[0]!='_')
{
ans=0;
int len=strlen(s);
for(int i=0;i<len;i++)
{
if(s[i]=='o')
ans+=a[i];
}
printf("%c",ans);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
编辑 (opens new window)
上次更新: 2022/05/18, 19:03:08