UVALive 4174

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

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<map>
  4 #include<vector>
  5 #include<math.h>
  6 #include<iostream>
  7 #include<map>
  8 using namespace std;
  9
 10 char str[100];
 11 int num[400];
 12 char anss[70];
 13 int cou;
 14 int tt;
 15
 16 void change()
 17 {
 18     int temp = (cou % 5);
 19     int ans = 0;
 20     tt = 0;
 21     char la;
 22     for (int i=0; i<temp; ++i)
 23     {
 24         num[cou++] = 0;
 25     }
 26     for (int i=0; i<cou; i+=5)
 27     {
 28         int t = 4;
 29         ans = 0;
 30         for (int j=i; j<i+5; ++j)
 31         {
 32             ans += pow(2, t) * num[j];
 33             t--;
 34         }
 35         if (ans >=1 && ans <= 26)
 36         {
 37             int hh = ans + int(‘A‘);
 38             hh -= 1;
 39             la = char(hh);
 40         }
 41         else if (ans == 30) la = ‘.‘;
 42         else if (ans == 29) la = ‘-‘;
 43         else if (ans == 28) la = ‘,‘;
 44         else if (ans == 27) la = ‘\‘‘;
 45         else if (ans == 0) la = ‘ ‘;
 46         else if (ans == 31) la = ‘?‘;
 47         anss[tt++] = la;
 48     }
 49 }
 50
 51
 52 int main()
 53 {
 54     cou = 0;
 55     while(gets(str))
 56     {
 57         int len = strlen(str);
 58         int cnt = 0;
 59         if (str[0] == ‘*‘)
 60         {
 61             change();
 62             int st = 0;
 63             while(anss[st] == ‘ ‘)
 64                 st++;
 65             int ed = tt-1;
 66             while(anss[ed] == ‘ ‘)
 67                 ed--;
 68             for (int i=st; i<=ed; ++i)
 69             {
 70                 cout << anss[i];
 71             }
 72             cout << endl;
 73             memset(num, 0, sizeof(num));
 74             memset(anss, 0, sizeof(anss));
 75             cou = 0;
 76             continue;
 77         }
 78         if (str[0] == ‘#‘)
 79             break;
 80
 81         for (int i=0; i<len; ++i)
 82         {
 83             cnt = 0;
 84             if (str[i] == ‘ ‘)
 85             {
 86                 int j;
 87                 for (j=i; ; j++)
 88                 {
 89                     if (str[j] != ‘ ‘)
 90                         break;
 91                     cnt++;
 92                 }
 93                 if (cnt % 2 == 1) num[cou++] = 0;
 94                 else num[cou++] = 1;
 95                 cnt = 0;
 96                 i = j;
 97             }
 98         }
 99     }
100     return 0;
101 }

LOoK

时间: 2024-12-25 04:49:28

UVALive 4174的相关文章

2015暑假训练赛个人赛(8.5)

  ID Origin Title   96 / 114 Problem A UVALive 4167 Parity  水题1 60 / 124 Problem B UVALive 4168 Lampyridae Teleportae  水题3 3 / 11 Problem C UVALive 4169 Hex Tile Equations   17 / 41 Problem D UVALive 4170 The Bridges of San Mochti   16 / 36 Problem E

UVALive 4848 Tour Belt

F - Tour Belt Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 4848 Description Korea has many tourist attractions. One of them is an archipelago (Dadohae in Korean), a cluster of small islands sca

UVALive 6467 Strahler Order 拓扑排序

这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ 以后能用CIN还是CIN吧 QAQ 贴代码了: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostre

UVALive 7077 Little Zu Chongzhi&#39;s Triangles (有序序列和三角形的关系)

这个题……我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了……结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小,想到了回溯每个棍的分组,最多分5组,结果发现超时了……最大是5^12 =  244,140,625,厉害呢…… 后来想贪心,首先想暴力出所有可能的组合,结果发现替换问题是一个难题……最后T T ,我就断片了.. 等看了别人的办法以后,我才发现我忽视了三角形的特性,和把数据排序以后的特点. 如果数据从

Gym 100299C &amp;&amp; UVaLive 6582 Magical GCD (暴力+数论)

题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点时,我们对gcd相同的只保留一个,那就是左端点最小的那个,只有这样才能保证是最大,然后删掉没用的. UVaLive上的数据有问题,比赛时怎么也交不过,后来去别的oj交就过了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu

UVALive 6511 Term Project

Term Project Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 651164-bit integer IO format: %lld      Java class name: Main 解题:强连通分量 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1

UVALive 6508 Permutation Graphs

Permutation Graphs Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 650864-bit integer IO format: %lld      Java class name: Main 解题:逆序数 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long l

UVALive 2659+HUST 1017+ZOJ 3209 (DLX

UVALive 2659 题目:16*16的数独.试了一发大白模板. /* * @author: Cwind */ //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <map> #include <algorithm> #include <cstdio> #include <cstring> #include

UVALive 5545 Glass Beads

Glass Beads Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 554564-bit integer IO format: %lld      Java class name: Main Once upon a time there was a famous actress. As you may expect, she played mostly