G - Gravity Gym - 101291G (字符的换位)
作者:互联网
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
char s[510][510];
int a,b;
cin >> a >> b;
for(int i=1; i<=a; i++)
{
cin >> s[i];
}
for(int i=0; i<b; i++)
{
int k=0;
for(int j=a; j>=1; j--)
{
if(s[j][i]=='o')
{
k=j;
while(s[k+1][i]!='#'&&s[k+1][i]!='o'&&k+1<=a)
{
++k;
}
swap(s[j][i],s[k][i]);
}
}
}
for(int i=1; i<=a; i++)
{
for(int j=0; j<b; j++)
{
cout << s[i][j];
}
cout << endl;
}
return 0;
}
标签:std,main,int,Gym,Gravity,&&,510,include,101291G 来源: https://blog.csdn.net/qq_44134712/article/details/96993837