50239. String Fusion
難度:2/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max(a,b) ((a)>(b)?(a):(b))
int main(){
int n, m; scanf("%d %d", &n, &m);
char s[2005] = {'\0'};
int max_len = 0;
for(int i = 0; i < m; i++){
char now_str[64]; int loc;
scanf("%s %d", now_str, &loc);
int len_str = strlen(now_str);
for(int j = 0; j < len_str; j++){
if(s[j + loc] == '\0') s[j + loc] = now_str[j];
else{
s[j + loc] = (char)(((int)s[j + loc] + (int)now_str[j]) / 2);
}
}
max_len = max(max_len, loc + len_str);
}
for(int i = 0; i < max_len; i++){
if(s[i] == '\0') s[i] = ' ';
}
printf("%s\n", s);
}