今天考的两题都段错误, 可本地能完美运行!
我不明白哪里出了问题, 请大家帮忙看看谢谢
//题目是这样的
//输入
//1234567
//2
//1 2
//3 4
//输出
//2244567
//就是说原来的字符串1234567
//做2次
//把1换成2
//把3换成4
//输出
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[100000] = {0};
unsigned long n, i, j;
scanf("%s", str);
unsigned long len = strlen(str);
scanf("%d", &n);
for(i = 0; i < n; i++) {
int a = 0;
int b = 0;
scanf("%d", &a);
scanf("%d", &b);
char a_c = '0' + a;
char b_c = '0' + b;
for(j = 0; j < len; j++) {
if(str[j] == a_c)
str[j] = b_c;
}
}
puts(str);
return 0;
}
//输入
//1234567
//2
//1 2
//3 4
//输出
//2244567
//就是说原来的字符串1234567
//做2次
//把1换成2
//把3换成4
//输出
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[100000] = {0};
unsigned long n, i, j;
scanf("%s", str);
unsigned long len = strlen(str);
scanf("%d", &n);
for(i = 0; i < n; i++) {
int a = 0;
int b = 0;
scanf("%d", &a);
scanf("%d", &b);
char a_c = '0' + a;
char b_c = '0' + b;
for(j = 0; j < len; j++) {
if(str[j] == a_c)
str[j] = b_c;
}
}
puts(str);
return 0;
}
全部评论
(2) 回帖