hdu3125Slash
http://acm.hdu.edu.cn/showproblem.php?pid=3125
字符串处理的水题~~
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100
char str[LEN];
int len;
int isURL()
{
int i;
for(i = 0; i < len; i++)
{
if(str[i] == ':')
break;
}
if((str[i + 1] == '/' || str[i + 1] == '\\') && (str[i + 2] == '/' || str[i + 2] == '\\'))
return 1;
return 0;
}
int isUnix()
{
if(str[0] == '/' || str[0] == '\\')
return 1;
return 0;
}
int isW()
{
int i;
for(i = 0; i < len; i++)
{
if(str[i] == ':')
break;
}
if(str[i + 1] == '/' || str[i + 1] == '\\')
{
if(str[i + 2] == '/' || str[i + 2] == '\\')
return 0;
return 1;
}
return 0;
}
int main()
{
int i, j;
int T;
scanf("%d", &T);
getchar();
while(T--)
{
gets(str);
len = strlen(str);
if(isURL())
{
printf("It's a URL!\n");
for(i = 0; i < len; i++)
{
if(str[i] == '\\')
putchar('/');
else
putchar(str[i]);
}
}
else if(isUnix())
{
printf("It's a path in Unix-like systems!\n");
for(i = 0; i < len; i++)
if(str[i] == '\\')
putchar('/');
else
putchar(str[i]);
}
else if(isW())
{
printf("It's a path in Windows system!\n");
for(i = 0; i < len; i++)
if(str[i] == '/')
putchar('\\');
else
putchar(str[i]);
}
putchar(10);
//printf("\n");
}
//system("pause");
return 0;
}