hdu 1986
뱀 모양 으로 숫자 를 채 우 는 방법 에 주의해 야 합 니 다. 그리고... 빈 칸 이 있 는 문자열 을 어떻게 입력 합 니까?
다음 코드 보기:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const char biao[27][6]={{"00000"},{"00001"},{"00010"},{"00011"},{"00100"},{"00101"},{"00110"},{"00111"},{"01000"},{"01001"},{"01010"},{"01011"},{"01100"},{"01101"},{"01110"},{"01111"},{"10000"},{"10001"},{"10010"},{"10011"},{"10100"},{"10101"},{"10110"},{"10111"},{"11000"},{"11001"},{"11010"}};
int map[30][30];
string s;
bool m[1000];
int main()
{
int T,r,c;
scanf("%d",&T);
for(int t=1;t<=T;t++)
{
memset(m,0,sizeof(m));
memset(map,-1,sizeof(map));
scanf("%d%d",&r,&c);
getchar();
/// gets(s); // s string char s[100], gets(s); 。
getline(cin,s);
int sum=0;
for( int i = 0; s[i]!='\0' ; i++ )
{
int k=0;
if(s[i]>='A' && s[i]<='Z') k=(int)(s[i]-'A')+1;
for(int j=0;j<5;j++){
m[++sum] = biao[k][j]-'0';
}
}
int tot=0,x,y;
x=0;y=0;
map[0][0] = m[++tot];
while( tot < sum ) ///
{
while(y+1<c && map[x][y+1]==-1) map[x][++y] = m[++tot];///
while(x+1<r && map[x+1][y]==-1) map[++x][y] = m[++tot];///
while(y-1>=0&& map[x][y-1]==-1) map[x][--y] = m[++tot];///
while(x-1>=0&& map[x-1][y]==-1) map[--x][y] = m[++tot];///
}
printf("%d ",t);
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
if(map[i][j]==-1) printf("0");
else printf("%d",map[i][j]);
}
printf("
");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.