######################我是分隔符#################################
#include <iostream>
#include <string>
using namespace std
void main()
{
string s
int count,i,j
cout<<"输入一行字符串:\n"
getline(cin,s)
for(count=0,j=s.size(),i=0i<j)
{
while(s[i]==' '&&i<j) i++
if(i<j) count++
while(s[i]!= ' '&&i<j) i++
}
cout<<"输入的字符串为:\n"<<s<<endl
cout<<"字符串中包含的单词数为:"<<count<<endl
}
一个三处错误:import javax.swing.*//下面JOptionPane是这个包里面的。
public class Project0 {
public static String InputWord
public static int sum=0
public static void main(String[] args){
InputWord=typeword()
countword(InputWord)
outputword()
//typeword
//countword
//outputword
}
public static String typeword(){
return(JOptionPane.showInputDialog(null,"Enter a word:"))
}
public static void countword(String word){
word=word.toLowerCase()
for (int i=0i<word.length()i++){ ///不是word.length
if (Character.isLetter(word.charAt(i))){//不是word.CharAt(i),下面同理
if (word.charAt(i)=='x'||word.charAt(i)=='q')
sum+=5
else if (word.charAt(i)=='a'||word.charAt(i)=='e'||word.charAt(i)=='i'||word.charAt(i)=='o'||word.charAt(i)=='u')
sum+=0
else
sum+=1
}
}
}
public static void outputword(){
JOptionPane.showMessageDialog(null,"the word is"+InputWord+"\n"+"Score: "+sum)
}
}
小错不断,并且这只是C不是C++#include <stdio.h>
#include <string.h>
main()
{ char src[81], dest[81]
int i, j
gets(src)
for(i=j=0*(src+i)!='\0'i++)
{if(*(src+i)!='a')
*(dest+j++)=*(src+i) //
else { *(dest+j++)='S'
*(dest+j++)='H'
*(dest+j++)='U'}}
*(dest+j)='\0' //
puts(dest)//
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)