游客 Signup | Login
中文 | En

3089 - 1999年秋浙江省计算机等级考试二级C 编程题(2)

编制程序,统计文本stdin中字符$出现的次数,并将结果写入文件stdout

Input

字符文本

Output

$次数

Examples

Input

as$dfkjhkjkjdhf
asdfkj$lskdfj
werijweirjo$wie 

Output

3

Hint


#include <stdio.h>
int main(){
  FILE *p;
  .....
  //p=fopen("data.txt","r");
  p=stdin;
  .....
  //p=fopen("res.txt","w");
  p=stdout;
  ....
  return 0; 
}

Solution C

#include<stdio.h> 
int main()
{
    char a[1000];
 int b=0;
 int i;
 for(i=0;scanf("%c",&a[i]),a[i]!=' ';i++)
 {
  if(a[i]=='$')
   b++;
 }
    printf("%d\n",b);
 return 0;
}

Solution C++

#include<iostream>
using namespace std;
int main()
{
	int ans=0;
	char c;
	while (cin>>c && c!=' ')
		if (c=='$') ans++;
	cout<<ans<<endl;
	return 0;
}

Hint


#include <stdio.h>
int main(){
  FILE *p;
  .....
  //p=fopen("data.txt","r");
  p=stdin;
  .....
  //p=fopen("res.txt","w");
  p=stdout;
  ....
  return 0; 
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题