00问答网
所有问题
C++ 二维数组 编写一个程序,输入两个字符串s1、s2
编写一个程序,输入两个字符串s1、s2,然后比较这两个字符串的大小,若s1>s2,输出1;若s1=s2,输出0;若s1<s2,输出一个 -1
必须用C++语言 CIN COUT
举报该问题
推荐答案 2015-06-15
#include <iostream>
#include <string>
#using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
if(s1>s2)
cout<<1<<endl;
else
if(s1==s2)
cout<<0<<endl;
else
cout<<-1<<endl;
return 0;
}
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://00.wendadaohang.com/zd/DerITerDB0TIT0ZeenB.html
相似回答
输入两个字符串s1
和
s2,
然后将s2接在s1后面,输出连接后的字符串
答:
include<
string
> using namespace std;int main(){ string str1;string str2;int pos;do { if((cin>>str1>>str2>>pos)&&(pos>=1)){ str1.insert(po
s-1,
str2);cout<<str1<<endl;} else { cout<<"Invalid Input"<<endl;break;} }while(false);return 0;} ...
输入两个字符串S1,s2,
判断s2是否为s1的子串
答:
void main(){ char s1[50]
,s2
[20];int i,j,t;gets(s1);gets(s2);for(i=0;s1[i]!='\0';i++){ t=i;if(s1[i]==s2[0]){ for(j=0;s2[j]!='\0';){ if(s1[i++]==s2[j++])continue;else { i=t;break;} } } } if(j==strlen(s2))printf("s2是s1的字串");...
C++程序
:要实现如下功能
,输入字符串s1,s2
,在s1中查找s2,并打印每个S2出...
答:
c++
用
string
标准实现方式:include <iostream>#include <string>using namespace std;int main(){ string str = "abcded fgeduied"; size_t pos = 0; int ncount = 0; while(1) { pos=((ncount==0)?0:pos+1);//第一次pos=0,再一次则要偏移一个位置了 pos...
输入两个字符串s1
和
s2,
然后将s2接在s1后面,输出连接后的字符串,不可以...
答:
using namespace std;char * myStrcat(char* destStr,const char* srcStr) //方法一
,数组
操作 { int srcLen = 0;int destLen = 0;while(srcStr[srcLen]!='\0'){ srcLen++;} while(destStr[destLen]!='\0'){ destLen++;} for(int i = 0 ; i<srcLen ; i++){ destStr[...
大家正在搜
二维数组怎么输入字符串
c语言二维数组字符串怎么输入
C 二维数组 字符串 初始值
二维数组以字符串输出
二维数组存储多个字符串
读入两个字符串s1和s2
字符串s1等于字符串s2
二维数组字符串
字符串能用二维数组表示吗