1.IP地址判断是否正确
2.一段字符空格和字母,数字个数
3.给整数输出二进制
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
int n, a, b, c, d;
scanf("%d", &n);
while (n--){
scanf("%d.%d.%d.%d", &a, &b, &c, &d);
if (a < 0 || b < 0 || c < 0 || d < 0 || a > 255 || b > 255 || c > 255 || d > 255)
printf("No!\n");
else
printf("Yes!\n");
}
system("pause");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char c;
int letters = 0, space = 0, digit = 0, others = 0;
while ((c = getchar())!= '\n')
{
if (c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z')
letters++;
else if (c == ' ')
space++;
else if (c >= '0'&&c <= '9')
digit++;
else
others++;
printf("char=%d space=%d digit=%d others=%d\n", letters, space, digit, others);
system("pause");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int num ;
cin >> num;
while(num)
{
cout << (num&1);
num = num >> 1;//把num转换成二进制表示后所有位向后移动一位,高位补0
}
cout <<endl;
system("pause");
return 0;
}