字符串修改 修改任意位置的数字字符 最终字符串不包含两个连续相同字符
不包含连续相同的字符,还是数字字符?字符串里只有数字字符码?
#include<stdio.h>
#include <string.h>
int main()
{
char s[100];
int len,i;
gets(s);
len = strlen(s);
for(i=1;i<len;i++)
{
if(s[i-1] == s[i])
{
if(s[i] != '9')
s[i] = '9';
else
s[i] = '8';
}
}
puts(s);
return 0;
}
import java.util.Scanner;
public class zifuchuan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int res = 0;
for (int i = 1; i < str.length(); i++) {
if(str.charAt(i) == str.charAt(i - 1)){
res++;
i++;
}
}
System.out.println(res);
}
}