ACM PKU 2105 IP Address 簡單題,讀數據時細心






























































# include <iostream.h>
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 4; ++j) {
int d = 0;
for (int k = 0; k < 8; ++k) {
char b;
cin >> b;
d = (2 * d + (b - '0'));
}
cout << d;
if (j < 3) {
cout << ".";
}
}
cout << endl;
}
return 0;
}
回復 更多評論
#include <stdio.h>
#include <stdlib.h>
int main()
{
int times,i,j;
scanf("%d",×);
char *p;
p=(char *)malloc(33*sizeof(char));
for(i=0;i<times;++i)
{
scanf("%s",p);
int a[4]={0},t=256;
for(j=0;j<32;j++)
{
t/=2;
a[j/8]+=(p[j]-'0')*t;
if(t==1)t=256;
}
printf("%d.%d.%d.%d\n",a[0],a[1],a[2],a[3]);
}
return 0;
} 回復 更多評論
只有注冊用戶登錄后才能發表評論。 | ||
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
![]() |
||
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
|
||
|