UVALive 4174

时间:2023-03-10 02:57:42
UVALive 4174

DES:给出一个字符串。连续空格的个数代表一个新的字符。奇数个表示0。偶数个表示1。然后根据这个码作为ASCII码。写出对应的字符。就是统计空格个数。二进制转换成十进制的小模拟。但是比赛的时候敲得很不顺。

 #include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<math.h>
#include<iostream>
#include<map>
using namespace std; char str[];
int num[];
char anss[];
int cou;
int tt; void change()
{
int temp = (cou % );
int ans = ;
tt = ;
char la;
for (int i=; i<temp; ++i)
{
num[cou++] = ;
}
for (int i=; i<cou; i+=)
{
int t = ;
ans = ;
for (int j=i; j<i+; ++j)
{
ans += pow(, t) * num[j];
t--;
}
if (ans >= && ans <= )
{
int hh = ans + int('A');
hh -= ;
la = char(hh);
}
else if (ans == ) la = '.';
else if (ans == ) la = '-';
else if (ans == ) la = ',';
else if (ans == ) la = '\'';
else if (ans == ) la = ' ';
else if (ans == ) la = '?';
anss[tt++] = la;
}
} int main()
{
cou = ;
while(gets(str))
{
int len = strlen(str);
int cnt = ;
if (str[] == '*')
{
change();
int st = ;
while(anss[st] == ' ')
st++;
int ed = tt-;
while(anss[ed] == ' ')
ed--;
for (int i=st; i<=ed; ++i)
{
cout << anss[i];
}
cout << endl;
memset(num, , sizeof(num));
memset(anss, , sizeof(anss));
cou = ;
continue;
}
if (str[] == '#')
break; for (int i=; i<len; ++i)
{
cnt = ;
if (str[i] == ' ')
{
int j;
for (j=i; ; j++)
{
if (str[j] != ' ')
break;
cnt++;
}
if (cnt % == ) num[cou++] = ;
else num[cou++] = ;
cnt = ;
i = j;
}
}
}
return ;
}

LOoK