标签:des style blog class code tar
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 869 | Accepted: 405 |
Description
Input
Output
Sample Input
2 2
AT
*O
6 7
AIM*DEN
*ME*ONE
UPON*TO
SO*ERIN
*SA*OR*
IES*DEA
0
Sample Output
puzzle #1:
Across
1.AT
3.O
Down
1.A
2.TO
puzzle #2:
Across
1.AIM
4.DEN
7.ME
8.ONE
9.UPON
11.TO
12.SO
13.ERIN
15.SA
17.OR
18.IES
19.DEA
Down
1.A
2.IMPOSE
3.MEO
4.DO
5.ENTIRE
6.NEON
9.US
10.NE
14.ROD
16.AS
18.I
20.A
这是一道字符串模拟题。给你一个字符矩阵,让你水平读,竖直读。遇到‘*‘或者换行,就输出读取的字符串,至于编号,则是第一行和第一列非‘*’的都要标号,其他的若该字符不是‘*’并且其前一个或是上一个字符若为‘*’则将其编号。
下面是我的代码:
1 #include <iostream> 2 #include <iomanip> 3 using namespace std; 4 char ch[12][12]; 5 int ch1[12][12]; 6 7 int main() 8 { 9 int r,c,i,j,k,m,puzzle=1; 10 while(cin>>r && r) 11 { 12 cin>>c; 13 memset(ch1,0,sizeof(ch1)); 14 for(i=0; i<r; i++) 15 for(j=0; j<c; j++) 16 cin>>ch[i][j]; 17 m = 1; 18 for(i=0; i<r; i++) //对字符进行编号 19 for(j=0; j<c; j++) 20 { 21 if(i==0 || j==0) 22 { 23 if(ch[i][j] != ‘*‘) 24 ch1[i][j] = m++; 25 } 26 else 27 { 28 if(ch[i][j] != ‘*‘) 29 if(ch[i-1][j]==‘*‘ || ch[i][j-1]==‘*‘) 30 ch1[i][j] = m++; 31 } 32 } 33 cout<<"puzzle #"<<puzzle++<<":"<<endl; 34 cout<<"Across"<<endl; 35 { 36 for(i=0; i<r; i++) 37 for(j=0; j<c; j++) 38 { 39 if(ch[i][j]!=‘*‘) 40 { 41 cout<<setw(3)<<ch1[i][j]<<"."<<ch[i][j]; 42 j++; 43 while(j<c && ch[i][j]!=‘*‘) 44 cout<<ch[i][j++]; 45 j--; 46 cout<<endl; 47 } 48 } 49 } 50 cout<<"Down"<<endl; 51 { 52 for(i=0; i<r; i++) 53 { 54 55 for(j=0; j<c; j++) 56 { 57 k=i; 58 if(ch[k][j]!=‘*‘) 59 { 60 cout<<setw(3)<<ch1[k][j]<<"."<<ch[k][j]; 61 ch[k][j] = ‘*‘; 62 k++; 63 while(k<r && ch[k][j]!=‘*‘) 64 { 65 cout<<ch[k][j]; 66 ch[k][j] = ‘*‘; 67 k++; 68 } 69 k--; 70 cout<<endl; 71 } 72 } 73 } 74 } 75 cout<<endl; 76 } 77 return 0; 78 }
poj 1888 Crossword Answers,布布扣,bubuko.com
标签:des style blog class code tar
原文地址:http://www.cnblogs.com/yazhou/p/3710260.html