- 【读入一行,把一行中的每一个word作为一个对象放入一个vector中】
int N;
scanf("%d",&N);
for(int i=1; i<=N; i++)
{
int w1,d1,w2,d2;
scanf("%d%d%d%d",&w1,&d1,&w2,&d2);
vector<string> line1;
vector<string> line2;
istringstream stream1(string1);
istringstream stream2(string2);
string word;
while(stream1>>word)
line1.push_back(word);
while(stream2>>word)
line2.push_back(word);
}
- 【字符串拼接,生成结果放入ostringstream,然后将其转换为string 并返回】
int** mat = new int*[rows];
for(int i = 0; i < rows; ++i)
{
mat[i] = new int[columns];
}
//生成结果并返回
string result="";
ostringstream stream;
int n = 0;
for(int i = 0; i < rows; ++i)
{
for(int j = 0; j < columns; ++j)
{
if(j !=columns-1)
{
stream<<mat[i][j]<<"*";
}
else
{
stream<<mat[i][j];
}
}
stream<<"\n";
}
result = stream.str();
return result;
- 【读入[4,6][2,7][6,8]格式的输入】
char c;
int al,ar;
cin>>c;
cin>>al;
cin>>c;
cin>>ar;
cin>>c;
int m[100],n[100];int i=0;
while(cin>>c)
{
if(c=='[')
{
int a,b;
cin>>a;
cin>>c;
cin>>b;
if(a<=al&&b>=al)
{
a=al;
if(a>=ar)
b=ar;
m[i]=a;
n[i]=b;
i++;
}
}
}
- 【输入为22 (5(4(11(7()())(2()()))())(8(13()())(4()(1()())))),后面的char一个个读入的问题】
int _tmain(int argc, _TCHAR* argv[])
{
stack<int> st;
int num;
char c;
while(cin>>num)
{
while(1)
{
c=getchar();
if(c==' '||c=='\n')continue;
if(c=='(')
{
st.push(0-(c-'0'));
continue;
}
if(isdigit(c)) //判断字符是否为数字
{
}
}
return 0;
}
}
- 【组数 组文字输入字符串问题】
3
ppeeefpffeefe
pefepeefe
peeef
peefe
peeef
peepefefe
int T;
string s1, s2;
cin >> T;
while(T--)
{
cin>>s1>> s2;
}
- 【 f-- + c-- + d-++e 处理此类输入问题,中间带空格】
char input1[220];
char input2[220];
while(gets(input1)!=NULL)
{
int len1=strlen(input1),len2=0;
for(int i=0;i<len1;i++) //处理掉输入中的空格
if(input1[i]!=' ')
input2[++len2]=input1[i];
int p=1;
if(input2[1]=='-') //处理第一个字母
{
}
else if(input2[1]=='+')
}
- 【最常规输入的问题】
1
0 2 0 4
0 3 0 1
1 1 1 1
2 4 4 2
1 6 3 2
int N;
scanf("%d",&N);
for(int i=1; i<=N; i++)
{
int w1,d1,w2,d2;
scanf("%d%d%d%d",&w1,&d1,&w2,&d2);
- 【常规输入】
3
2
acm
ibm
3
acm
malform
mouse
2
ok
ok
using namespace std;
const int maxn=1010,maxm=30;
char s[maxn];//not char s[maxm]
int in[maxm],out[maxm],p[maxm];//indgree,outdgree
int _tmain(int argc, _TCHAR* argv[])
{
int T;
scanf("%d",&T);
while(T--)
{
int i,N;
scanf("%d",&N);
memset(in,0,sizeof(in));
memset(out,0,sizeof(out));
for(i=0;i<N;i++)
{
scanf("%s",&s);
}
}
}