c++题目求大佬!字符串!求源代码!非常急qwq救救孩子 今天要用 在线等
1个回答
2018-05-29
展开全部
#include <stdio.h>
int main()
{
int count[26] = {0};
char ch;
do
{
ch = getchar();
if ('a' <= ch && ch <= 'z')
{
count[ch - 'a'] ++;
}
else if ('A' <= ch && ch <= 'Z')
{
count[ch - 'A'] ++;
}
}while (ch != '#');
for (ch = 'a'; ch <= 'z'; ch ++)
{
// 只显示不为 0 的字符.
if (count[ch - 'a'] != 0)
{
printf("%c %d\n", ch, count[ch - 'a']);
}
}
return 0;
}
#include <stdio.h>
int main()
{
char ch;
ch = getchar();
while (ch != '#')
{
if ('a' <= ch && ch <= 'z')
{
ch += 'A' - 'a';
}
putchar(ch);
ch = getchar();
}
return 0;
}
#include <stdio.h>
int string_compare(const char *s1, const char *s2)
{
while (*s1 != '\0' || *s2 != '\0')
{
if (*s1 < *s2)
{
return -1;
}
if (*s1 > *s2)
{
return 1;
}
s1 ++;
s2 ++;
}
return 0;
}
void compare_and_print(const char *s1, const char *s2)
{
if (s1 && s2)
{
printf("string_compare(\"%s\", \"%s\") returns %d.\n", s1, s2, string_compare(s1, s2));
}
else
{
printf("string can't be NULL.\n");
}
}
int main()
{
compare_and_print("a", "b");
compare_and_print("b", "a");
compare_and_print("a", "aa");
compare_and_print("aa", "a");
compare_and_print("123", "123");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i;
int sum = 0;
for (i = 1; i < argc; i ++)
{
sum += atoi(argv[i]);
}
printf("%d\n", sum);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询