第二题字符串连续变换…改了仨版本了,都是测试用例OK,提交超时。求助
题意大概是
//输入
//1234567
//2
//1 2
//2 4
//输出
//4434567
//就是说原来的字符串1234567
//做2次
//把1换成2
//把2换成4
//输出
//1234567
//2
//1 2
//2 4
//输出
//4434567
//就是说原来的字符串1234567
//做2次
//把1换成2
//把2换成4
//输出
#include <stdio.h> #include <string.h> int main() { char s[1000001] = {""}; scanf("%s", s); int n = 0; scanf("%d", &n); char map[] = {'0','1','2','3','4','5','6','7','8','9'}; for(int i = 0; i < n ; i++){ int a,b; scanf("%d %d", &a, &b); map[a] = b+'0'; } for(int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (map[j] == '0'+i) map[j] = map[i]; } } for(int i = 0; i < strlen(s); i++){ s[i] = map[s[i] - '0']; } printf("%s",s); return 0; }
全部评论
(1) 回帖