TOJ 3007. Decoding
2014-07-25 19:20
218 查看
终于AC了!!!!!!!!!!!!一直是Presentation Error,知道是末尾不能有空格的原因,但是就是改不好,而且不能用while循环来判断,因为会超时,我的方法是这样的:
用一个变量fla代表出现的空格数,初始化为0;只要遇到是空格的情况先不要急着输出,而是累加fla,在下一个非空格的字符输出前输出,而且fla还累计空格个数。
我能够说我提交了20多遍都是错误的吗?
Chip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The sender encodes
an intermediate format using the following rules:
1. The text is formed with uppercase letters [A-Z] and <space>.
2. Each text character will be represented by decimal values as follows:
< space> = 0, A = 1, B = 2, C = 3, ..., Y = 25, Z = 26
The sender enters the 5 digit binary representation of the characters' values in a spiral pattern along the matrix as shown below. The matrix is padded out with zeroes (0) to fill the matrix completely. For example, if the text to encode is: "ACM" and R=4
and C=4, the matrix would be filled in as follows:
The bits in the matrix are then concatenated together in row major order and sent to the receiver. The example above would be encoded as: 0000110100101100
Each dataset consists of a single line of input containing R (1 ≤
R ≤ 20), a space, C (1 ≤ C ≤ 20), a space, and a string of binary digits that represents the contents of the matrix (R * C binary digits). The binary digits are in
row major order.
decoded text message. You should throw away any trailing spaces and/or partial characters found while decoding.
AC代码:
用一个变量fla代表出现的空格数,初始化为0;只要遇到是空格的情况先不要急着输出,而是累加fla,在下一个非空格的字符输出前输出,而且fla还累计空格个数。
我能够说我提交了20多遍都是错误的吗?
Chip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The sender encodes
an intermediate format using the following rules:
1. The text is formed with uppercase letters [A-Z] and <space>.
2. Each text character will be represented by decimal values as follows:
< space> = 0, A = 1, B = 2, C = 3, ..., Y = 25, Z = 26
The sender enters the 5 digit binary representation of the characters' values in a spiral pattern along the matrix as shown below. The matrix is padded out with zeroes (0) to fill the matrix completely. For example, if the text to encode is: "ACM" and R=4
and C=4, the matrix would be filled in as follows:
The bits in the matrix are then concatenated together in row major order and sent to the receiver. The example above would be encoded as: 0000110100101100
Input
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.Each dataset consists of a single line of input containing R (1 ≤
R ≤ 20), a space, C (1 ≤ C ≤ 20), a space, and a string of binary digits that represents the contents of the matrix (R * C binary digits). The binary digits are in
row major order.
Output
For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and thedecoded text message. You should throw away any trailing spaces and/or partial characters found while decoding.
Sample Input
4 4 4 0000110100101100 5 2 0110000010 2 6 010000001001 5 5 0100001000011010110000010
Sample Output
1 ACM 2 HI 3 HI 4 HI HO
AC代码:
<pre name="code" class="cpp">
<span style="font-size:10px;"></span><pre name="code" class="cpp">#include<iostream> #include<string> using namespace std; int main(){ int N,r,c,l,i,j,k,a[21][21],b[410],flag[21][21],m; char t; cin>>N; for(l=1;l<=N;l++){ cin>>r>>c; for(i=0;i<r;i++) for(j=0;j<c;j++){ cin>>t; a[i][j]=t-'0'; flag[i][j]=0; } flag[0][0]=1; m=r*c; k=0; i=0; j=0; int f=1;//1,2,3,4分别代表向右,下,左,上 while(true){ b[k]=a[i][j]; k++; if(k==m) break; if(f==1){ if(j==c-1||flag[i][j+1]==1){ f=2; i++; } else j++; } else if(f==2){ if(i==r-1||flag[i+1][j]==1){ f=3; j--; } else i++; } else if(f==3){ if(j==0||flag[i][j-1]==1){ f=4; i--; } else j--; } else if(f==4){ if(i==0||flag[i-1][j]==1){ f=1; j++; } else i--; } flag[i][j]=1; } cout<<l<<" "; int fla=0; for(i=0;i<=m-5;i=i+5){ k=b[i]; for(j=i+1;j<i+5;j++) { k=k*2; k=k+b[j]; } if(k==0){ fla++; } else{ if(fla!=0){ for(int kk=0;kk<fla;kk++) cout<<" "; fla=0; } char s=k+'A'-1; cout<<s; } } cout<<endl; } return 0; }
相关文章推荐
- TOJ--2119--最小生成树和map
- TOJ---3128---bfs(打印路径)
- TOJ Monkey Vines
- TOJ 1399. Blocks (打表或者暴力)
- TOJ 1401. All in All
- 【TOJ 3751.】Card Game【KM】
- 【TOJ 3872.】Matrix【最小割】
- 【TOJ 3282】 Rain's Array
- Java报错 信息: Character decoding failed.
- toj 4074 CF 319C 斜率优化dp
- ZOJ 1450 HDU 3007 (最小圆覆盖)
- toj 2196 优先队列和堆的用法
- TOJ 4105 Lines Counting (树状数组)
- TOJ 4110 A+B
- leetoj Search in Rotated Sorted Array
- [TOJ 3978] Probability II
- [TOJ 2663] Concert Hall Scheduling
- TOJ 1547. To and Fro【栈和队列】
- CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法
- TOJ 2548.Celebrity jeopardy