C题为什么0分?
#include<stdio.h> #include<utility> #include<string.h> using namespace std; int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); char mat[n][m+1]; memset(mat,'*',sizeof(mat)); pair<int,int>pos; for(int i=0;i<n;i++) mat[i][m]='\0'; for(int i=0;i<k;i++){ scanf("%d%d",&pos.first,&pos.second); pos.first--; pos.second--; if(mat[pos.first][pos.second]=='.') continue; else{ if(mat[pos.first][pos.second]=='*'&&pos.first>0){ if(mat[pos.first-1][pos.second]=='.') mat[pos.first][pos.second]='.'; else{ int j=pos.first; while(mat[j][pos.second]=='*'&&j>0) j--; mat[j][pos.second]='.'; } } else if(mat[pos.first][pos.second]=='*'&&pos.first==0) mat[pos.first][pos.second]=='.'; } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++) printf("%c",mat[i][j]); printf("\n"); } }
为什么这种写法能过样例,但是数据都不对,有没有改进的办法?