如何将c语言中的scanf和printf改成C++。以及printf(%c)和(%d)改C++区别
比如这个
#include<iostream>
#include<math.h>
#include <stdio.h>
#include<string.h>
#include <algorithm>
int main ()
{
int n;
while (scanf ("%d", &n) == 1 && n) {
static char str[100010];
scanf ("%s", str);
if (n % 2 == 1) {
printf ("-1 ");
continue;
}
int h_tot = 0, t_tot = 0;
for (int i=0; i<n; ++i) {
if (str[i] == 'T')
++t_tot;
else
++h_tot;
}
if (h_tot % 2 == 1 || t_tot % 2 == 1) {
printf ("-1 ");
continue;
}
int h = 0, t = 0;
for (int i=0; i<n/2; ++i) {
if (str[i] == 'T')
++t;
else
++h;
}
if (t * 2 == t_tot && h * 2 == h_tot) {
printf ("1 %d ", n / 2);
continue;
}
for (int i=n/2; i<n; ++i) {
if (str[i] == 'T')
++t;
else
++h;
if (str[i - n/2] == 'T')
--t;
else
--h;
if (t * 2 == t_tot && h * 2 == h_tot) {
printf ("2 %d %d ", i + 1 - n/2, i + 1);
break;
} else if (i == n - 1) {
printf ("-1 ");
}
}
}
return 0;
}
printf(%c)和(%d)改C++是有区别的,我查了很多,但是都没有说到,而且有的说没区别,但是在HDU里面,当成没区别去改是会出错的,所以不要说没区别了。希望有大佬解答一下,完美的有多少悬赏追加多少
下一篇:语言文件受损如何修复
上一篇:samba怎么正确安装