疑惑:
1.while (条件)
此处条件为何不能 用scanf("%c", &right);来实现
而是取用cin?
1.1 如果我想用scanf 又该如何处理呢?
2.cout << sqrt(n);
为何我直接用printf("%d", sqrt(n));系统却会报错?然后输出不了
2.1 解决方法难道只有 用cout 或者 定义一个新的变量来解决吗?
报错原因
[警告] format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} [-Wformat=]
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int main (void)
{
int n = 0;
int point = 1, count[200*200+1] = {0};
char left = '0', right;
while (cin >> right)
{
n++;
if (right != left)
{
point ++;
count[point]++;
}
else
{
count[point]++;
}
left = right;
}
cout << sqrt(n);
for (int i=1; i<=point; i++)
printf(" %d", count[i]);
return 0;
}